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.
This commit is contained in:
Ivan Nieto 2018-08-28 15:25:16 -05:00 committed by snipe
parent 652548957d
commit 0014ef054b

View file

@ -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);