33 lines
1.4 KiB
PHP
33 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Events\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
use Modules\Events\Models\Event;
|
|
use Modules\Events\Models\Venue;
|
|
|
|
final class EventController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
return view('events::admin.index', ['events' => Event::with(['venue'])->withCount('registrations')->orderBy('starts_at')->paginate(20), 'venues' => Venue::orderBy('name')->get()]);
|
|
}
|
|
|
|
public function store(Request $r): RedirectResponse
|
|
{
|
|
Event::create($r->validate(['venue_id' => ['nullable', 'exists:event_venues,id'], 'title' => ['required', 'string', 'max:255'], 'slug' => ['required', 'string', 'max:255', 'unique:events,slug'], 'summary' => ['nullable', 'string'], 'description' => ['nullable', 'string'], 'starts_at' => ['required', 'date'], 'ends_at' => ['nullable', 'date', 'after:starts_at'], 'status' => ['required', 'in:draft,published,cancelled,completed'], 'capacity' => ['nullable', 'integer', 'min:1'], 'price' => ['required', 'numeric', 'min:0']]) + ['registration_open' => $r->boolean('registration_open')]);
|
|
|
|
return back()->with('status', 'Event created.');
|
|
}
|
|
|
|
public function destroy(Event $event): RedirectResponse
|
|
{
|
|
$event->delete();
|
|
|
|
return back()->with('status', 'Event deleted.');
|
|
}
|
|
}
|