added EventController
This commit is contained in:
parent
0eefc87fbf
commit
6ca1c00b76
3 changed files with 45 additions and 3 deletions
|
@ -21,4 +21,5 @@ class Event extends Model
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $hidden = [];
|
protected $hidden = [];
|
||||||
|
}
|
41
app/Http/Controllers/EventController.php
Normal file
41
app/Http/Controllers/EventController.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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']);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue