codefocus /
managedcache
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Codefocus\ManagedCache\Traits; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | |||
| 7 | trait IdentifiesEloquentModels |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Return whether the specified class name is an Eloquent Model. |
||
| 11 | * |
||
| 12 | * @param mixed $value |
||
| 13 | * |
||
| 14 | * @return bool |
||
| 15 | */ |
||
| 16 | protected function isModel($value): bool |
||
| 17 | { |
||
| 18 | return is_object($value) && is_subclass_of($value, Model::class); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Returns an array containing the Model class name, and the model id. |
||
| 23 | * The id is null if $model is a string. |
||
| 24 | * |
||
| 25 | * @param Model|string $model |
||
| 26 | * @param int|null $modelId (default: null) |
||
| 27 | * |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | protected function getModelClassNameAndId($model, ?int $modelId = null): array |
||
| 31 | { |
||
| 32 | if ($this->isModel($model)) { |
||
| 33 | return [ |
||
| 34 | get_class($model), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | $modelId ?? $model->getKey(), |
||
| 36 | ]; |
||
| 37 | } |
||
| 38 | |||
| 39 | return [ |
||
| 40 | $model, |
||
| 41 | $modelId, |
||
| 42 | ]; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |