-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserListRequest.php
More file actions
48 lines (35 loc) · 1.09 KB
/
UserListRequest.php
File metadata and controls
48 lines (35 loc) · 1.09 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
<?php
namespace App\Http\Requests;
use App\Classes\UserQuery;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Validation\Validator;
class UserListRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'orderBy' => 'in:first_name,last_name,organisation,industry_type,created_at,last_logged_in_at',
'sort' => 'in:asc,desc',
'filters.search' => 'nullable|string|min:3|max:191'
];
}
public function getUserQuery(): UserQuery
{
$orderBy = $this->get('orderBy', 'created_at');
$sort = $this->get('sort', 'asc');
$userQuery = new UserQuery();
$userQuery->setOrderBy($orderBy);
$userQuery->setSort($sort);
$filters = $this->get('filters', $this->get('filters\\', []));
foreach ($filters as $column => $value) {
$userQuery->addFilter(rtrim($column, '\\'), $value);
}
return $userQuery;
}
}