adrema/app/Form/Actions/FormUpdateAction.php

67 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2024-01-01 18:29:33 +01:00
<?php
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\ActionRequest;
class FormUpdateAction
{
use AsAction;
use HasValidation;
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
...$this->globalRules(),
2024-02-02 01:05:45 +01:00
'description' => 'required|array',
'description.time' => 'required|integer',
'description.blocks' => 'required|array',
'description.version' => 'required|string',
2024-01-01 18:29:33 +01:00
'excerpt' => 'required|string|max:130',
'from' => 'required|date',
'to' => 'required|date',
'registration_from' => 'present|nullable|date',
'registration_until' => 'present|nullable|date',
2024-04-19 17:42:59 +02:00
'mail_top' => 'array',
'mail_bottom' => 'array',
2024-01-01 18:29:33 +01:00
];
}
/**
* @param array<string, mixed> $attributes
*/
public function handle(Form $form, array $attributes): Form
{
$form->update($attributes);
return $form;
}
/**
* @return array<string, mixed>
*/
public function getValidationAttributes(): array
{
return [
...$this->globalValidationAttributes(),
'from' => 'Start',
'to' => 'Ende',
2024-02-02 01:05:45 +01:00
'description.blocks' => 'Beschreibung',
2024-01-01 18:29:33 +01:00
];
}
public function asController(Form $form, ActionRequest $request): JsonResponse
{
$this->handle($form, $request->validated());
Succeeded::message('Veranstaltung aktualisiert.')->dispatch();
return response()->json([]);
}
}