adrema/app/Form/Actions/ParticipantUpdateAction.php

56 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2024-07-12 20:15:24 +02:00
<?php
namespace App\Form\Actions;
use App\Form\Models\Participant;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ParticipantUpdateAction
{
use AsAction;
2024-07-12 20:42:30 +02:00
/**
* @return array<string, mixed>
*/
2024-07-12 20:15:24 +02:00
public function rules(): array
{
2024-07-13 17:54:23 +02:00
/** @var Participant */
$participant = request()->route('participant');
return $participant->form->getRegistrationRules();
2024-07-12 20:15:24 +02:00
}
2024-07-13 17:54:23 +02:00
/**
* @return array<string, mixed>
*/
public function getValidationAttributes(): array
{
/** @var Participant */
$participant = request()->route('participant');
return $participant->form->getRegistrationAttributes();
}
/**
* @return array<string, mixed>
*/
public function getValidationMessages(): array
2024-07-12 20:15:24 +02:00
{
2024-07-13 17:54:23 +02:00
/** @var Participant */
$participant = request()->route('participant');
2024-07-12 20:15:24 +02:00
2024-07-13 17:54:23 +02:00
return $participant->form->getRegistrationMessages();
}
public function handle(Participant $participant, ActionRequest $request): JsonResponse
{
$participant->update(['data' => [...$participant->data, ...$request->validated()]]);
ExportSyncAction::dispatch($participant->form->id);
2024-07-12 20:15:24 +02:00
Succeeded::message('Teilnehmer*in bearbeitet.')->dispatch();
return response()->json([]);
}
}