Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class Siblings extends Base |
||
10 | { |
||
11 | use HasLimit { |
||
|
|||
12 | limit as baseLimit; |
||
13 | } |
||
14 | |||
15 | /** |
||
16 | * Match the eagerly loaded results to their parents. |
||
17 | * |
||
18 | * @param array $models |
||
19 | * @param \Illuminate\Database\Eloquent\Collection $results |
||
20 | * @param string $relation |
||
21 | * @return array |
||
22 | */ |
||
23 | 50 | public function match(array $models, Collection $results, $relation) |
|
24 | { |
||
25 | 50 | parent::match($models, $results, $relation); |
|
26 | |||
27 | 50 | if (!$this->parent->exists && !$this->andSelf) { |
|
28 | 30 | $limit = $this->query->getQuery()->groupLimit; |
|
29 | |||
30 | 30 | if ($limit) { |
|
31 | 10 | foreach ($models as $model) { |
|
32 | 10 | $model->setRelation( |
|
33 | 10 | $relation, |
|
34 | 10 | $model->getRelation($relation)->take($limit['value'] - 1) |
|
35 | 10 | ); |
|
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | 50 | return $models; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Set the "limit" value of the query. |
||
45 | * |
||
46 | * @param int $value |
||
47 | * @return $this |
||
48 | */ |
||
49 | 30 | public function limit($value) |
|
56 | } |
||
57 | } |
||
58 |