From 194a0a81e0d7217f93f5bbf8bff42c57fc3e6d58 Mon Sep 17 00:00:00 2001 From: Jan Felix Wiebe Date: Fri, 15 Nov 2019 22:26:54 +0100 Subject: [PATCH] added items --- app/Http/Controllers/ItemController.php | 40 +++++++++++++++++++++++++ app/Item.php | 25 ++++++++++++++++ routes/web.php | 9 ++++++ 3 files changed, 74 insertions(+) create mode 100644 app/Http/Controllers/ItemController.php create mode 100644 app/Item.php diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php new file mode 100644 index 0000000..d12c543 --- /dev/null +++ b/app/Http/Controllers/ItemController.php @@ -0,0 +1,40 @@ +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); + } +} \ No newline at end of file diff --git a/app/Item.php b/app/Item.php new file mode 100644 index 0000000..4c73966 --- /dev/null +++ b/app/Item.php @@ -0,0 +1,25 @@ +group(['prefix' => 'api'], function () use ($router) { $router->post('containers', ['uses' => 'ContainerController@create']); $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']); }); \ No newline at end of file