1 | <?php |
||
14 | trait HasRelationships |
||
15 | { |
||
16 | /** |
||
17 | * List of available relations. |
||
18 | * |
||
19 | * @var string[] |
||
20 | */ |
||
21 | protected $relations = []; |
||
22 | |||
23 | /** |
||
24 | * A list of autoloaded default relations. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $load = []; |
||
29 | |||
30 | /** |
||
31 | * Get a list of whitelisted relations, including nested relations. |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | public function whitelistedRelations(): array |
||
43 | |||
44 | /** |
||
45 | * Get a list of default relations, including nested relations. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function defaultRelations(): array |
||
57 | |||
58 | /** |
||
59 | * Extract a list of nested relations from the transformers provided in the |
||
60 | * list of relations. |
||
61 | * |
||
62 | * @param array $relations |
||
63 | * @param callable $nestedCallback |
||
64 | * @return array |
||
65 | */ |
||
66 | protected function getNestedRelations(array $relations, callable $nestedCallback): array |
||
80 | |||
81 | /** |
||
82 | * Normalize relations to force a key value structure. |
||
83 | * |
||
84 | * @param array $relations |
||
85 | * @return array |
||
86 | */ |
||
87 | protected function normalizeRelations(array $relations): array |
||
97 | |||
98 | /** |
||
99 | * Normalize relations to force a key value structure. |
||
100 | * |
||
101 | * @param string $relation |
||
102 | * @return \Closure|null |
||
103 | */ |
||
104 | 14 | protected function getQueryConstraint(string $relation) |
|
114 | |||
115 | /** |
||
116 | * Resolve a relationship from a model instance. |
||
117 | * |
||
118 | * @param \Illuminate\Database\Eloquent\Model $model |
||
119 | * @param string $identifier |
||
120 | * @return mixed |
||
121 | */ |
||
122 | 7 | protected function resolveRelation(Model $model, string $identifier) |
|
132 | |||
133 | /** |
||
134 | * Get a related transformer class mapped to a relation identifier. |
||
135 | * |
||
136 | * @param string $identifier |
||
137 | * @return string|null |
||
138 | */ |
||
139 | 10 | protected function getRelatedTransformerName(string $identifier) |
|
145 | |||
146 | /** |
||
147 | * Resolve a transformer from a class name string. |
||
148 | * |
||
149 | * @param string $transformer |
||
150 | * @return mixed |
||
151 | */ |
||
152 | protected abstract function resolveTransformer(string $transformer); |
||
153 | } |