added EventController

This commit is contained in:
Jan Felix Wiebe 2019-11-15 22:10:28 +01:00
parent 0eefc87fbf
commit 6ca1c00b76
3 changed files with 45 additions and 3 deletions

View file

@ -21,4 +21,5 @@ class Event extends Model
* *
* @var array * @var array
*/ */
protected $hidden = []; protected $hidden = [];
}

View file

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

View file

@ -16,9 +16,9 @@ $router->get('/', function () use ($router) {
}); });
$router->group(['prefix' => 'api'], function () use ($router) { $router->group(['prefix' => 'api'], function () use ($router) {
$router->get('events', ['uses' => 'EventController@showAllAuthors']); $router->get('events', ['uses' => 'EventController@showAllEvents']);
$router->get('events/{id}', ['uses' => 'EventController@showOneAuthor']); $router->get('events/{id}', ['uses' => 'EventController@showOneEvent']);
$router->post('events', ['uses' => 'EventController@create']); $router->post('events', ['uses' => 'EventController@create']);