Total Complexity | 3 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | trait IsAranguentRelation |
||
11 | { |
||
12 | /** |
||
13 | * Get all of the primary keys for an array of models. |
||
14 | * |
||
15 | * @param array<mixed> $models |
||
16 | * @param string|null $key |
||
17 | * @return array<int, int|string> |
||
18 | */ |
||
19 | 9 | protected function getKeys(array $models, $key = null) |
|
20 | { |
||
21 | // The original function orders the results associatively by value which means the keys reorder too. |
||
22 | // However, a list of keys with unordered numeric keys will be recognized as an object down the line |
||
23 | // for json casting while we need a list of keys. |
||
24 | |||
25 | 9 | $keys = collect($models)->map(function ($value) use ($key) { |
|
|
|||
26 | 9 | return $key ? $value->getAttribute($key) : $value->getKey(); |
|
27 | 9 | })->values()->unique(null, true)->all(); |
|
28 | |||
29 | 9 | sort($keys); |
|
30 | |||
31 | 9 | return $keys; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Add the constraints for a relationship count query. |
||
36 | * |
||
37 | * @return Builder |
||
38 | */ |
||
39 | 1 | public function getRelationExistenceCountQuery(Builder $query, Builder $parentQuery) |
|
45 | 1 | ); |
|
46 | } |
||
48 |