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

109 lines
2.9 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;
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));
2020-06-22 12:53:00 +00:00
return view("admin.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()
{
2020-06-22 12:53:00 +00:00
return view("admin.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"
]);
$event = new Event($requestBody);
$event->save();
2020-06-22 12:53:00 +00:00
return view("admin.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)
{
2020-06-22 12:53:00 +00:00
return view("admin.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-18 06:01:42 +00:00
public function edit(Event $id)
{
2020-06-22 12:53:00 +00:00
return view("admin.events.edit", [ "event" => $id ]);
}
/**
* 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-19 06:15:24 +00:00
public function update(Request $request, Event $id)
{
2020-06-19 06:15:24 +00:00
$requestBody = $request->validate([
"name" => "unique:events|max:255",
"description" => "max:255"
]);
$id->update($requestBody);
$id->save();
2020-06-22 12:53:00 +00:00
return view("admin.events.update");
}
/**
* 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-18 06:01:42 +00:00
public function destroy(Event $id)
{
2020-06-18 06:01:42 +00:00
$id->delete();
2020-06-22 12:53:00 +00:00
return view("admin.events.destroy");
}
}