c3lf-system-3/app/Http/Controllers/ItemController.php
2019-12-17 01:33:40 +01:00

68 lines
2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Item;
use App\Event;
use Illuminate\Http\Request;
class ItemController extends Controller
{
public function showAllItems()
{
return response()->json(Item::all());
}
public function showByEvent($event)
{
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(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')
->get());
}
public function searchByEvent($event, $query)
{
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(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());
}
public function showOneItem($event, $id)
{
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(Item::find($id));
}
public function create($event, Request $request)
{
$eid = Event::where('slug','=',$event)->first()->eid;
$data = $request->all();
$data['eid'] = $eid;
$item = Item::create($request->all());
return response()->json($item, 201);
}
public function update($event, $id, Request $request)
{
$eid = Event::where('slug','=',$event)->first()->eid;
$item = Item::findOrFail($id);
$item->update($request->all());
return response()->json($item, 200);
}
public function delete($event, $id)
{
$eid = Event::where('slug','=',$event)->first()->eid;
Item::findOrFail($id)->delete();
return response()->json(array("satus"=>'Deleted Successfully'), 200);
}
}