53 lines
1.2 KiB
PHP
53 lines
1.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)->get());
|
|
}
|
|
|
|
public function searchByEvent($event, $query)
|
|
{
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
return response()->json(Item::where('eid','=',$eid)->get()); //TODO actually search
|
|
}
|
|
|
|
public function showOneItem($event, $id)
|
|
{
|
|
return response()->json(Item::find($id));
|
|
}
|
|
|
|
public function create($event, Request $request)
|
|
{
|
|
$item = Item::create($request->all());
|
|
return response()->json($item, 201);
|
|
}
|
|
|
|
public function update($event, $id, Request $request)
|
|
{
|
|
$item = Item::findOrFail($id);
|
|
$item->update($request->all());
|
|
|
|
return response()->json($event, $item, 200);
|
|
}
|
|
|
|
public function delete($event, $id)
|
|
{
|
|
Item::findOrFail($id)->delete();
|
|
return response('Deleted Successfully', 200);
|
|
}
|
|
}
|