From 0014ef054b6f03d31b9557dd74f98545eb500ee9 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Date: Tue, 28 Aug 2018 15:25:16 -0500 Subject: [PATCH] Search functionality in accessories/{accessory} issue #5471: (#6070) From the collection of users displayed just filtered the data with the method where() and concat() for the user can search for first name or last name. The solution is case sensitive. --- app/Http/Controllers/Api/AccessoriesController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index e078999c0f..1669bd3181 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -132,7 +132,7 @@ class AccessoriesController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function checkedout($id) + public function checkedout($id, Request $request) { $this->authorize('view', Accessory::class); @@ -143,6 +143,11 @@ class AccessoriesController extends Controller $accessory->lastCheckoutArray = $accessory->lastCheckout->toArray(); $accessory_users = $accessory->users; + + if($request->filled('search')){ + $accessory_users = $accessory_users->where('first_name', $request->input('search'))->concat($accessory_users->where('last_name', $request->input('search'))); + } + $total = $accessory_users->count(); return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $accessory_users, $total);