c3lf-system-3/app/Http/Controllers/ItemController.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2019-11-15 21:26:54 +00:00
<?php
namespace App\Http\Controllers;
use App\Item;
2019-12-02 17:41:40 +00:00
use App\Event;
2019-11-15 21:26:54 +00:00
use Illuminate\Http\Request;
class ItemController extends Controller
{
2019-11-30 12:47:54 +00:00
public function showAllItems()
2019-11-15 21:26:54 +00:00
{
return response()->json(Item::all());
}
2019-12-01 17:30:25 +00:00
public function showByEvent($event)
2019-11-30 12:47:54 +00:00
{
2019-12-02 17:41:40 +00:00
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(Item::where('eid','=',$eid)
->join('containers','item.cid','=','container.cid')
->leftJoin('files','item.iid','=','files.iid')
->get());
2019-11-30 12:47:54 +00:00
}
2019-12-01 17:30:25 +00:00
public function searchByEvent($event, $query)
{
return showByEvent($event); //TODO actually search
2019-12-01 17:30:25 +00:00
}
public function showOneItem($event, $id)
2019-11-15 21:26:54 +00:00
{
return response()->json(Item::find($id));
}
2019-12-01 17:30:25 +00:00
public function create($event, Request $request)
2019-11-30 12:47:54 +00:00
{
2019-11-15 21:26:54 +00:00
$item = Item::create($request->all());
return response()->json($item, 201);
}
2019-12-01 17:30:25 +00:00
public function update($event, $id, Request $request)
2019-11-15 21:26:54 +00:00
{
$item = Item::findOrFail($id);
$item->update($request->all());
2019-12-01 17:30:25 +00:00
return response()->json($event, $item, 200);
2019-11-15 21:26:54 +00:00
}
2019-12-01 17:30:25 +00:00
public function delete($event, $id)
2019-11-15 21:26:54 +00:00
{
Item::findOrFail($id)->delete();
return response('Deleted Successfully', 200);
}
2019-11-30 12:47:54 +00:00
}