2024-02-08 21:04:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Actions;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
2024-02-08 23:13:59 +01:00
|
|
|
use App\Form\Models\Participant;
|
2024-02-08 21:04:00 +01:00
|
|
|
use App\Form\Resources\ParticipantResource;
|
2024-03-08 02:19:07 +01:00
|
|
|
use App\Form\Scopes\ParticipantFilterScope;
|
2024-02-08 21:04:00 +01:00
|
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class ParticipantIndexAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
2024-02-08 23:13:59 +01:00
|
|
|
/**
|
|
|
|
* @return LengthAwarePaginator<Participant>
|
|
|
|
*/
|
2024-03-08 02:19:07 +01:00
|
|
|
public function handle(Form $form, ParticipantFilterScope $filter): LengthAwarePaginator
|
2024-02-08 21:04:00 +01:00
|
|
|
{
|
2024-03-08 02:19:07 +01:00
|
|
|
return $form->participants()->withFilter($filter)->with('form')->paginate(15);
|
2024-02-08 21:04:00 +01:00
|
|
|
}
|
|
|
|
|
2024-02-08 23:09:51 +01:00
|
|
|
public function asController(Form $form): AnonymousResourceCollection
|
2024-02-08 21:04:00 +01:00
|
|
|
{
|
2024-03-08 02:19:07 +01:00
|
|
|
$filter = ParticipantFilterScope::fromRequest(request()->input('filter'));
|
|
|
|
return ParticipantResource::collection($this->handle($form, $filter))
|
2024-02-08 21:04:00 +01:00
|
|
|
->additional(['meta' => ParticipantResource::meta($form)]);
|
|
|
|
}
|
|
|
|
}
|