- Update API: events, users, policies, routes, resources, migrations - Remove deprecated models/resources (customers, setlists, invitations, etc.) - Refresh admin app and docs; remove apps/band Made-with: Cursor
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\V1\StoreEventRequest;
|
|
use App\Http\Requests\Api\V1\UpdateEventRequest;
|
|
use App\Http\Resources\Api\V1\EventResource;
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class EventController extends Controller
|
|
{
|
|
public function index(Organisation $organisation): AnonymousResourceCollection
|
|
{
|
|
Gate::authorize('viewAny', [Event::class, $organisation]);
|
|
|
|
$events = $organisation->events()
|
|
->latest('start_date')
|
|
->paginate();
|
|
|
|
return EventResource::collection($events);
|
|
}
|
|
|
|
public function show(Organisation $organisation, Event $event): JsonResponse
|
|
{
|
|
Gate::authorize('view', $event);
|
|
|
|
abort_unless($event->organisation_id === $organisation->id, 404);
|
|
|
|
return $this->success(new EventResource($event->load('organisation')));
|
|
}
|
|
|
|
public function store(StoreEventRequest $request, Organisation $organisation): JsonResponse
|
|
{
|
|
Gate::authorize('create', [Event::class, $organisation]);
|
|
|
|
$event = $organisation->events()->create($request->validated());
|
|
|
|
return $this->created(new EventResource($event));
|
|
}
|
|
|
|
public function update(UpdateEventRequest $request, Organisation $organisation, Event $event): JsonResponse
|
|
{
|
|
Gate::authorize('update', $event);
|
|
|
|
abort_unless($event->organisation_id === $organisation->id, 404);
|
|
|
|
$event->update($request->validated());
|
|
|
|
return $this->success(new EventResource($event->fresh()));
|
|
}
|
|
}
|