| Total Complexity | 3 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | trait ModelQueries |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var AbstractModel|Model |
||
| 16 | */ |
||
| 17 | protected $model; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The Eloquent Model class |
||
| 21 | * |
||
| 22 | * @var AbstractModel|Model |
||
| 23 | */ |
||
| 24 | protected $modelClass; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var int|null |
||
| 28 | */ |
||
| 29 | protected $related_model_key; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array Array of relationships that should be eager loaded with the model |
||
| 33 | */ |
||
| 34 | protected $eagerLoadRelationships = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Set the $model property value |
||
| 38 | * |
||
| 39 | * - if an integer model_key value is passed, find the model |
||
| 40 | * - if a model instance is passed, declare the model |
||
| 41 | * |
||
| 42 | * @param int|Model|null $model |
||
| 43 | * @return Model|null |
||
| 44 | */ |
||
| 45 | private function resolveModel($model) { |
||
| 46 | // todo: should there be a relatedModelClass or modelRelation attr? |
||
| 47 | // $model is a Model class |
||
| 48 | if ($model instanceof $this->modelClass) { |
||
| 49 | return $model; |
||
| 50 | } |
||
| 51 | |||
| 52 | // Find the model using a model key |
||
| 53 | else { |
||
| 54 | return $this->modelQuery()->with($this->eagerLoadRelationships)->find($model); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Retrieve the Model's query builder |
||
| 60 | * |
||
| 61 | * @return QueryBuilder|Builder |
||
| 62 | */ |
||
| 63 | protected function modelQuery() |
||
| 66 | } |
||
| 67 | } |
||
| 68 |