| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | public function search(Request $request) |
||
| 13 | { |
||
| 14 | // If the user is not allowed to perform this action |
||
| 15 | if (Gate::forUser(backpack_user())->denies('enroll-students')) { |
||
| 16 | abort(403); |
||
| 17 | } |
||
| 18 | |||
| 19 | $data = []; |
||
| 20 | |||
| 21 | if ($request->has('q')) { |
||
| 22 | $search = $request->q; |
||
| 23 | |||
| 24 | $data = DB::table('students') |
||
| 25 | ->select('students.id', 'users.firstname', 'users.lastname') |
||
| 26 | ->join('users', 'students.id', '=', 'users.id') |
||
| 27 | ->where('users.firstname', 'LIKE', "%$search%") |
||
| 28 | ->orWhere('users.lastname', 'LIKE', "%$search%") |
||
| 29 | ->get(); |
||
| 30 | } |
||
| 31 | |||
| 32 | return response()->json($data); |
||
| 33 | } |
||
| 35 |