2019-11-15 22:26:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Item;
|
2019-12-02 18:41:40 +01:00
|
|
|
use App\Event;
|
2019-11-15 22:26:54 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ItemController extends Controller
|
|
|
|
{
|
|
|
|
|
2019-11-30 13:47:54 +01:00
|
|
|
public function showAllItems()
|
2019-11-15 22:26:54 +01:00
|
|
|
{
|
|
|
|
return response()->json(Item::all());
|
|
|
|
}
|
|
|
|
|
2019-12-01 18:30:25 +01:00
|
|
|
public function showByEvent($event)
|
2019-11-30 13:47:54 +01:00
|
|
|
{
|
2019-12-02 18:41:40 +01:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-12-05 13:05:44 +01:00
|
|
|
return response()->json(Item::where('eid','=',$eid)
|
2019-12-05 13:09:25 +01:00
|
|
|
->join('containers','items.cid','=','containers.cid')
|
2019-12-05 13:07:03 +01:00
|
|
|
->leftJoin('files','items.iid','=','files.iid')
|
2019-12-15 20:34:47 +01:00
|
|
|
->select('items.*','files.hash as file', 'containers.name as box')
|
2019-12-05 13:05:44 +01:00
|
|
|
->get());
|
2019-11-30 13:47:54 +01:00
|
|
|
}
|
|
|
|
|
2019-12-01 18:30:25 +01:00
|
|
|
public function searchByEvent($event, $query)
|
|
|
|
{
|
2019-12-11 21:36:43 +01:00
|
|
|
$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')
|
2019-12-15 20:34:47 +01:00
|
|
|
->select('items.*','files.hash as file', 'containers.name as box')
|
|
|
|
->where('items.description', 'like' , '%'.base64_decode ( $query , true).'%')
|
2019-12-11 21:36:43 +01:00
|
|
|
->get());
|
2019-12-01 18:30:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showOneItem($event, $id)
|
2019-11-15 22:26:54 +01:00
|
|
|
{
|
2019-12-17 01:33:40 +01:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-11-15 22:26:54 +01:00
|
|
|
return response()->json(Item::find($id));
|
|
|
|
}
|
|
|
|
|
2019-12-01 18:30:25 +01:00
|
|
|
public function create($event, Request $request)
|
2019-11-30 13:47:54 +01:00
|
|
|
{
|
2019-12-17 01:33:40 +01:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
|
|
$data = $request->all();
|
|
|
|
$data['eid'] = $eid;
|
2019-11-15 22:26:54 +01:00
|
|
|
$item = Item::create($request->all());
|
|
|
|
return response()->json($item, 201);
|
|
|
|
}
|
|
|
|
|
2019-12-01 18:30:25 +01:00
|
|
|
public function update($event, $id, Request $request)
|
2019-11-15 22:26:54 +01:00
|
|
|
{
|
2019-12-17 01:33:40 +01:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-11-15 22:26:54 +01:00
|
|
|
$item = Item::findOrFail($id);
|
|
|
|
$item->update($request->all());
|
|
|
|
|
2019-12-15 18:15:41 +01:00
|
|
|
return response()->json($item, 200);
|
2019-11-15 22:26:54 +01:00
|
|
|
}
|
|
|
|
|
2019-12-01 18:30:25 +01:00
|
|
|
public function delete($event, $id)
|
2019-11-15 22:26:54 +01:00
|
|
|
{
|
2019-12-17 01:33:40 +01:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-11-15 22:26:54 +01:00
|
|
|
Item::findOrFail($id)->delete();
|
2019-12-15 20:34:47 +01:00
|
|
|
return response()->json(array("satus"=>'Deleted Successfully'), 200);
|
2019-11-15 22:26:54 +01:00
|
|
|
}
|
2019-11-30 13:47:54 +01:00
|
|
|
}
|