Conditions | 3 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3.1406 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | 3 | public function index(Request $request) |
|
14 | { |
||
15 | 3 | $user = $request->user(); |
|
16 | |||
17 | 3 | if ($user->cant('viewAny', User::class)) { |
|
18 | 2 | abort(401); |
|
19 | } |
||
20 | |||
21 | 1 | $search = $request->search; |
|
22 | |||
23 | 1 | $query = User::query(); |
|
24 | |||
25 | 1 | if ($search) { |
|
26 | $query->where(function (Builder $query) use ($search) { |
||
27 | $query->where('name', 'LIKE', "%{$search}%") |
||
28 | ->orWhere('email', 'LIKE', "%{$search}%"); |
||
29 | }); |
||
30 | } |
||
31 | |||
32 | 1 | $users = $query->orderBy('created_at', 'DESC')->paginate(30); |
|
33 | |||
34 | 1 | return UserResource::collection($users)->additional(['authorized_actions' => (new User)->authorizedActions()]); |
|
35 | } |
||
50 |