adrema/app/Form/Actions/FormIndexAction.php

36 lines
936 B
PHP
Raw Normal View History

2023-12-31 22:35:13 +01:00
<?php
namespace App\Form\Actions;
2024-01-29 22:07:33 +01:00
use App\Form\FilterScope;
2023-12-31 22:35:13 +01:00
use App\Form\Models\Form;
use App\Form\Resources\FormResource;
use Illuminate\Pagination\LengthAwarePaginator;
use Inertia\Inertia;
use Inertia\Response;
2024-01-29 22:07:33 +01:00
use Lorisleiva\Actions\ActionRequest;
2023-12-31 22:35:13 +01:00
use Lorisleiva\Actions\Concerns\AsAction;
class FormIndexAction
{
use AsAction;
/**
* @return LengthAwarePaginator<Form>
*/
2024-01-29 22:07:33 +01:00
public function handle(string $filter): LengthAwarePaginator
2023-12-31 22:35:13 +01:00
{
2024-02-08 20:29:46 +01:00
return FilterScope::fromRequest($filter)->getQuery()->query(fn ($query) => $query->withCount('participants'))->paginate(15);
2023-12-31 22:35:13 +01:00
}
2024-01-29 22:07:33 +01:00
public function asController(ActionRequest $request): Response
2023-12-31 22:35:13 +01:00
{
2024-01-01 18:29:33 +01:00
session()->put('menu', 'form');
session()->put('title', 'Veranstaltungen');
2023-12-31 22:35:13 +01:00
return Inertia::render('form/Index', [
2024-01-29 22:07:33 +01:00
'data' => FormResource::collection($this->handle($request->input('filter', ''))),
2023-12-31 22:35:13 +01:00
]);
}
}