From 906201313e3f1d7bd31740094b3a7ef94c3b1c9b Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 26 Dec 2019 20:21:40 +0100 Subject: [PATCH] 'fuzzy' search update --- app/Http/Controllers/ItemController.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index a9c9983..b736b3f 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -29,12 +29,14 @@ class ItemController extends Controller public function searchByEvent($event, $query) { $eid = Event::where('slug','=',$event)->first()->eid; - return response()->json(Item::where('eid','=',$eid) + $query_tokens = explode(" ",base64_decode ( $query , true)); + $q = Item::where('eid','=',$eid) ->join('containers','items.cid','=','containers.cid') ->leftJoin('files','items.iid','=','files.iid') - ->select('items.*','files.hash as file', 'containers.name as box') - ->where('items.description', 'like' , '%'.base64_decode ( $query , true).'%') - ->get()); + ->select('items.*','files.hash as file', 'containers.name as box'); + foreach ($query_tokens as $token) + $g = $q->where('items.description','like','%'.$token.'%'); + return response()->json($q->get()); } public function showOneItem($event, $id)