111 lines
3.0 KiB
PHP
111 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Event;
|
|
use App\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
class EventController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource..
|
|
*
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$events = Event::query()->paginate($request->input("limit", 20));
|
|
|
|
return Response::detect("admin.events.index", [ "events" => $events]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
return Response::detect("admin.events.create");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$requestBody = $request->validate([
|
|
"name" => "required|unique:events|max:255",
|
|
"description" => "required|max:255"
|
|
]);
|
|
|
|
$event = new Event($requestBody);
|
|
|
|
$event->save();
|
|
|
|
return Response::detect("admin.events.store");
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param Event $id
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function show(Event $id)
|
|
{
|
|
return Response::detect("admin.events.show", [ "event" => $id ]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.-
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function edit(Event $id)
|
|
{
|
|
return Response::detect("admin.events.edit", [ "event" => $id ]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function update(Request $request, Event $id)
|
|
{
|
|
$requestBody = $request->validate([
|
|
"name" => "unique:events|max:255",
|
|
"description" => "max:255"
|
|
]);
|
|
|
|
$id->update($requestBody);
|
|
$id->save();
|
|
|
|
return Response::detect("admin.events.update");
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param Event $id
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
* @throws \Exception
|
|
*/
|
|
public function destroy(Event $id)
|
|
{
|
|
$id->delete();
|
|
|
|
return Response::detect("admin.events.destroy");
|
|
}
|
|
}
|