1public function index(Request $request)
2 {
3 $query = User::where('company_id', $request->input('company_id'));
4
5 if ($request->has('last_name'))
6 {
7 $query->where('last_name', 'LIKE', '%' . $request->input('last_name') . '%');
8 }
9
10 if ($request->has('name'))
11 {
12 $query->where(function ($q) use ($request)
13 {
14 return $q->where('first_name', 'LIKE', $request->input('name') . '%')
15 ->orWhere('last_name', 'LIKE', '%' . $request->input('name') . '%');
16 });
17 }
18
19 $query->whereHas('roles', function ($q) use ($request)
20 {
21 return $q->whereIn('id', $request->input('roles'));
22 })
23 ->whereHas('clients', function ($q) use ($request)
24 {
25 return $q->whereHas('industry_id', $request->input('industry'));
26 });
27
28 return $query->get();
29 }