Conditions | 2 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function getFilters(array $filters): Collection|LengthAwarePaginator |
||
22 | { |
||
23 | $data = Post::query(); |
||
24 | |||
25 | if ($filters['tags'] !== null) { |
||
26 | $tags = array_filter((array) $filters['tags']); |
||
27 | |||
28 | $data = $data->whereHas('tags', function (Builder $query) use ($tags): void { |
||
29 | $query->whereIn('tags.id', $tags); |
||
30 | }); |
||
31 | } |
||
32 | |||
33 | $orderBy = Arr::get($filters, 'order_by', 'updated_at'); |
||
34 | $order = Arr::get($filters, 'order', 'desc'); |
||
35 | |||
36 | $data = $data |
||
37 | ->wherePublished() |
||
38 | ->orderBy($orderBy, $order); |
||
39 | |||
40 | return $data->paginate((int) $filters['per_page']); |
||
41 | } |
||
43 |