This commit is contained in:
j3d1 2020-01-18 20:53:46 +01:00
parent d4e0d3859e
commit 836fb96f42
4 changed files with 77 additions and 27 deletions

View file

@ -20,10 +20,7 @@ class ItemController extends Controller
public function showByEvent($event)
{
$eid = Event::where('slug','=',$event)->first()->eid;
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
->join('containers','items.cid','=','containers.cid')
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
->select('items.*','currentfiles.hash as file', 'containers.name as box');
$q = Item::byEvent($eid);
return response()->json($q->get());
}
@ -31,29 +28,26 @@ class ItemController extends Controller
{
$eid = Event::where('slug','=',$event)->first()->eid;
$query_tokens = explode(" ",base64_decode ( $query , true));
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
->join('containers','items.cid','=','containers.cid')
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
->select('items.*','currentfiles.hash as file', 'containers.name as box');
$q = Item::byEvent($eid);
foreach ($query_tokens as $token)
$q = $q->where('items.description','like','%'.$token.'%');
if(!empty($token))
$q = $q->where('items.description','like','%'.$token.'%');
return response()->json($q->get());
}
public function showOneItem($event, $id)
{
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(Item::find($id));
return response()->json(Item::byEvent($eid)->where('item_uid', '=', $id)->first());
}
public function create($event, Request $request)
{
$eid = Event::where('slug','=',$event)->first()->eid;
$uid = Item::withTrashed()->where('eid',$eid)->max('item_uid') + 1;
$newitem = $request->except(['dataImage']);
$newitem['eid'] = "".$eid;
$newitem['item_uid'] = $uid;
$newitem['wo'] = "";
$newitem['wann'] = "";
$item = Item::create($newitem);
if ($request->get('dataImage')) {
@ -95,7 +89,7 @@ class ItemController extends Controller
$item['file'] = $hash;
}
}
return response()->json($item, 200);
return response()->json(Item::find($item['item_uid']), 200);
}
public function delete($event, $id)