-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the cache count system to use the model objects instead of th…
…e DB facade.
- Loading branch information
1 parent
c24a0f3
commit f49a0b0
Showing
22 changed files
with
219 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Eloquence\Behaviours; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
|
||
class CacheConfig | ||
{ | ||
public function __construct(readonly string $relationName, readonly string $countField) {} | ||
|
||
/** | ||
* Returns the actual Relation object - such as BelongsTo. This method makes a call to the relationship | ||
* method specified on the model object, and is used to infer data about the relationship. | ||
*/ | ||
public function relation(Model $model): Relation | ||
{ | ||
return $model->{$this->relationName}(); | ||
} | ||
|
||
/** | ||
* Returns -a- related model object - this object is actually empty, and is found on the query builder, used to | ||
* infer certain information abut the relationship that cannot be found on CacheConfig::relation. | ||
* | ||
* @param Model $model | ||
* @return Model | ||
*/ | ||
public function emptyRelatedModel(Model $model): Model | ||
{ | ||
return $this->relation($model)->getQuery()->getModel(); | ||
} | ||
|
||
public function foreignKeyName(Model $model): string | ||
{ | ||
return $this->relation($model)->getForeignKeyName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.