added containers

This commit is contained in:
Jan Felix Wiebe 2019-11-15 22:15:58 +01:00
parent 6ca1c00b76
commit 58618259a5
3 changed files with 81 additions and 9 deletions

25
app/Container.php Normal file
View file

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

View file

@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers;
use App\Container;
use Illuminate\Http\Request;
class ContainerController extends Controller
{
public function showAllContainers()
{
return response()->json(Container::all());
}
public function showOneContainer($id)
{
return response()->json(Container::find($id));
}
public function create(Request $request)
{
$container = Container::create($request->all());
return response()->json($container, 201);
}
public function update($id, Request $request)
{
$container = Container::findOrFail($id);
$container->update($request->all());
return response()->json($container, 200);
}
public function delete($id)
{
Container::findOrFail($id)->delete();
return response('Deleted Successfully', 200);
}
}

View file

@ -16,13 +16,19 @@ $router->get('/', function () use ($router) {
}); });
$router->group(['prefix' => 'api'], function () use ($router) { $router->group(['prefix' => 'api'], function () use ($router) {
// events
$router->get('events', ['uses' => 'EventController@showAllEvents']); $router->get('events', ['uses' => 'EventController@showAllEvents']);
$router->get('events/{id}', ['uses' => 'EventController@showOneEvent']); $router->get('events/{id}', ['uses' => 'EventController@showOneEvent']);
$router->post('events', ['uses' => 'EventController@create']); $router->post('events', ['uses' => 'EventController@create']);
$router->delete('events/{id}', ['uses' => 'EventController@delete']); $router->delete('events/{id}', ['uses' => 'EventController@delete']);
$router->put('events/{id}', ['uses' => 'EventController@update']); $router->put('events/{id}', ['uses' => 'EventController@update']);
}); });
$router->group(['prefix' => 'api'], function () use ($router) {
// containers
$router->get('containers', ['uses' => 'ContainerController@showAllContainers']);
$router->get('containers/{id}', ['uses' => 'ContainerController@showOneContainer']);
$router->post('containers', ['uses' => 'ContainerController@create']);
$router->delete('containers/{id}', ['uses' => 'ContainerController@delete']);
$router->put('containers/{id}', ['uses' => 'ContainerController@update']);
});