added items

This commit is contained in:
Jan Felix Wiebe 2019-11-15 22:26:54 +01:00
parent 58618259a5
commit 194a0a81e0
3 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers;
use App\Item;
use Illuminate\Http\Request;
class ItemController extends Controller
{
public function showAllEvents()
{
return response()->json(Item::all());
}
public function showOneEvent($id)
{
return response()->json(Item::find($id));
}
public function create(Request $request)
{
$item = Item::create($request->all());
return response()->json($item, 201);
}
public function update($id, Request $request)
{
$item = Item::findOrFail($id);
$item->update($request->all());
return response()->json($item, 200);
}
public function delete($id)
{
Item::findOrFail($id)->delete();
return response('Deleted Successfully', 200);
}
}

25
app/Item.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'iid', 'bezeichnung', 'wann', 'wo', 'eid', 'cid'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [];
}

View file

@ -32,3 +32,12 @@ $router->group(['prefix' => 'api'], function () use ($router) {
$router->delete('containers/{id}', ['uses' => 'ContainerController@delete']);
$router->put('containers/{id}', ['uses' => 'ContainerController@update']);
});
$router->group(['prefix' => 'api'], function () use ($router) {
// items
$router->get('items', ['uses' => 'ItemController@showAllItems']);
$router->get('items/{id}', ['uses' => 'ItemController@showOneItem']);
$router->post('items', ['uses' => 'ItemController@create']);
$router->delete('items/{id}', ['uses' => 'ItemController@delete']);
$router->put('items/{id}', ['uses' => 'ItemController@update']);
});