2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-18 06:01:42 +00:00
|
|
|
use App\Event;
|
2020-06-10 06:33:06 +00:00
|
|
|
use App\User;
|
2020-06-09 07:05:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class EventController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2020-06-10 06:33:06 +00:00
|
|
|
* Display a listing of the resource..
|
2020-06-09 07:05:07 +00:00
|
|
|
*
|
2020-06-18 06:01:42 +00:00
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-10 06:33:06 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-18 06:01:42 +00:00
|
|
|
$events = Event::query()->paginate($request->input("limit", 20));
|
2020-06-10 06:33:06 +00:00
|
|
|
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.index", [ "events" => $events]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.create");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
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-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.store");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-18 06:01:42 +00:00
|
|
|
public function show(Event $id)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.show", [ "event" => $id ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-09 08:45:16 +00:00
|
|
|
* Show the form for editing the specified resource.-
|
2020-06-09 07:05:07 +00:00
|
|
|
*
|
|
|
|
* @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-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-18 06:01:42 +00:00
|
|
|
public function edit(Event $id)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.edit", [ "event" => $id ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-19 06:15:24 +00:00
|
|
|
public function update(Request $request, Event $id)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
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-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.update");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-18 06:01:42 +00:00
|
|
|
public function destroy(Event $id)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-18 06:01:42 +00:00
|
|
|
$id->delete();
|
|
|
|
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("admin.events.destroy");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
}
|