Ekapp/skolehjem/app/Http/Controllers/EventController.php

111 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2020-06-18 06:01:42 +00:00
use App\Event;
use App\User;
use Illuminate\Http\Request;
2020-06-24 06:23:15 +00:00
use Illuminate\Http\Response;
class EventController extends Controller
{
/**
* Display a listing of the resource..
*
2020-06-18 06:01:42 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
2020-06-18 06:01:42 +00:00
$events = Event::query()->paginate($request->input("limit", 20));
return Response::detect("events.index", [ "events" => $events]);
}
/**
* Show the form for creating a new resource.
*
2020-06-18 06:01:42 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
return Response::detect("events.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
2020-06-18 06:01:42 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function store(Request $request)
{
2020-06-18 06:01:42 +00:00
$requestBody = $request->validate([
"name" => "required|unique:events|max:255",
"description" => "required|max:255",
"date" => "required"
2020-06-18 06:01:42 +00:00
]);
$event = new Event($requestBody);
$event->save();
return Response::detect("events.store");
}
/**
* Display the specified resource.
*
2020-06-18 06:01:42 +00:00
* @param Event $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
2020-06-18 06:01:42 +00:00
public function show(Event $id)
{
return Response::detect("events.show", [ "event" => $id ]);
}
/**
2020-06-09 08:45:16 +00:00
* Show the form for editing the specified resource.-
*
* @param int $id
2020-06-18 06:01:42 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
2020-06-30 06:52:11 +00:00
public function edit($id)
{
2020-06-30 06:52:11 +00:00
$event = Event::find($id);
return Response::detect("events.edit", [ "event" => $event ]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
2020-06-19 06:15:24 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
2020-06-30 06:52:11 +00:00
public function update(Request $request, $id)
{
2020-06-30 06:52:11 +00:00
$data = $request->all();
2020-06-19 06:15:24 +00:00
2020-06-30 06:52:11 +00:00
$event = Event::find($id);
$event->update($data);
$event->save();
2020-06-19 06:15:24 +00:00
2020-06-30 06:52:11 +00:00
return Response::detect("events.update", [ "event" => $event]);
}
/**
* Remove the specified resource from storage.
*
2020-06-18 06:01:42 +00:00
* @param Event $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Exception
*/
2020-06-29 12:48:31 +00:00
public function destroy($id)
{
2020-06-29 12:48:31 +00:00
$link = Event::find($id);
$link->delete();
return redirect()->route("events.index");
}
}