ProjectFilter.php
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace App\ModelFilters;
use App\Support\ModelFilter;
use Arr;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as Query;
class ProjectFilter extends ModelFilter
{
public $relations = [
'master' => ['masterName' => 'nickName']
];
/**
* @param string $name
* @return void
*/
public function name(string $name): void
{
$this->whereLike('name', $name);
}
/**
* @param int|array $status
* @return void
*/
public function status(int|array $status): void
{
$this->whereIn('status', Arr::wrap($status));
}
/**
* @param int|array $status
* @return void
*/
public function isPromote(int|array $status): void
{
$this->whereIn('is_promote', Arr::wrap($status));
}
/**
* @param int|array $status
* @return void
*/
public function isCanApply(int|array $status): void
{
$this->whereIn('is_can_apply', Arr::wrap($status));
}
public function masterOrManager(array|int $userId): void
{
$this->where(fn(Builder $query) => $query->whereIn('master_id', Arr::wrap($userId))
->orWhereExists(fn(Query $query) => $query->selectRaw(1)->from('user_has_projects')->whereColumn('user_has_projects.project_id', 'projects.id')->whereIn('user_has_projects.user_id', Arr::wrap($userId)))
);
}
/**
* @param $manage
* @return void
*/
public function manager($manage): void
{
$this->whereRelation('managers', fn(Builder $query) => $query->whereIn('users.id', Arr::wrap($manage)));
}
}