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