added items
This commit is contained in:
parent
58618259a5
commit
194a0a81e0
3 changed files with 74 additions and 0 deletions
40
app/Http/Controllers/ItemController.php
Normal file
40
app/Http/Controllers/ItemController.php
Normal 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
25
app/Item.php
Normal 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 = [];
|
||||||
|
}
|
|
@ -31,4 +31,13 @@ $router->group(['prefix' => 'api'], function () use ($router) {
|
||||||
$router->post('containers', ['uses' => 'ContainerController@create']);
|
$router->post('containers', ['uses' => 'ContainerController@create']);
|
||||||
$router->delete('containers/{id}', ['uses' => 'ContainerController@delete']);
|
$router->delete('containers/{id}', ['uses' => 'ContainerController@delete']);
|
||||||
$router->put('containers/{id}', ['uses' => 'ContainerController@update']);
|
$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']);
|
||||||
});
|
});
|
Loading…
Reference in a new issue