1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Api\Services; |
4
|
|
|
|
5
|
|
|
use CSlant\Blog\Api\Models\PostView; |
|
|
|
|
6
|
|
|
use CSlant\Blog\Core\Http\Responses\Base\BaseHttpResponse; |
7
|
|
|
use CSlant\Blog\Core\Models\Post; |
8
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator; |
9
|
|
|
use Illuminate\Database\Eloquent\Builder; |
10
|
|
|
use Illuminate\Support\Arr; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PostService |
14
|
|
|
* |
15
|
|
|
* @package CSlant\Blog\Api\Services |
16
|
|
|
* |
17
|
|
|
* @method BaseHttpResponse httpResponse() |
18
|
|
|
*/ |
19
|
|
|
class PostService |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Get posts by filters. |
23
|
|
|
* |
24
|
|
|
* @param array<string, mixed> $filters |
25
|
|
|
* |
26
|
|
|
* @return LengthAwarePaginator<Post> |
27
|
|
|
*/ |
28
|
|
|
public function getCustomFilters(array $filters): LengthAwarePaginator |
29
|
|
|
{ |
30
|
|
|
$data = Post::query(); |
31
|
|
|
|
32
|
|
|
if ($filters['tags'] !== null) { |
33
|
|
|
$tags = array_filter((array) $filters['tags']); |
34
|
|
|
|
35
|
|
|
$data = $data->whereHas('tags', function (Builder $query) use ($tags): void { |
36
|
|
|
$query->whereIn('tags.id', $tags); |
37
|
|
|
}); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($filters['categories'] !== null) { |
41
|
|
|
$categories = array_filter((array) $filters['categories']); |
42
|
|
|
|
43
|
|
|
$data = $data->whereHas('categories', function (Builder $query) use ($categories): void { |
44
|
|
|
$query->whereIn('categories.id', $categories); |
45
|
|
|
}); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($filters['categories_exclude'] !== null) { |
49
|
|
|
$data = $data |
50
|
|
|
->whereHas('categories', function (Builder $query) use ($filters): void { |
51
|
|
|
$query->whereNotIn('categories.id', array_filter((array) $filters['categories_exclude'])); |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($filters['exclude'] !== null) { |
56
|
|
|
$data = $data->whereNotIn('id', array_filter((array) $filters['exclude'])); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($filters['include'] !== null) { |
60
|
|
|
$data = $data->whereNotIn('id', array_filter((array) $filters['include'])); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($filters['author'] !== null) { |
64
|
|
|
$data = $data->whereIn('author_id', array_filter((array) $filters['author'])); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if ($filters['author_exclude'] !== null) { |
68
|
|
|
$data = $data->whereNotIn('author_id', array_filter((array) $filters['author_exclude'])); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($filters['featured'] !== null) { |
72
|
|
|
$data = $data->where('is_featured', $filters['featured']); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ($filters['search'] !== null) { |
76
|
|
|
$keyword = isset($filters['search']) ? (string) $filters['search'] : null; |
77
|
|
|
$data = $this->search($data, $keyword); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$orderBy = Arr::get($filters, 'order_by', 'updated_at'); |
81
|
|
|
$order = Arr::get($filters, 'order', 'desc'); |
82
|
|
|
|
83
|
|
|
$data = $data |
84
|
|
|
->wherePublished() |
85
|
|
|
->orderBy($orderBy, $order); |
86
|
|
|
|
87
|
|
|
return $data->paginate((int) $filters['per_page']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths