2023-12-27 22:54:58 +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 FormStoreAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
use HasValidation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...$this->globalRules(),
|
2024-02-02 01:05:45 +01:00
|
|
|
'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',
|
2023-12-31 21:46:52 +01:00
|
|
|
'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-12 23:29:18 +01:00
|
|
|
'header_image' => 'required|exclude',
|
2024-04-15 16:23:32 +02:00
|
|
|
'mailattachments' => 'present|array|exclude',
|
2024-05-27 18:30:05 +02:00
|
|
|
'is_active' => 'boolean',
|
2024-05-27 18:49:11 +02:00
|
|
|
'is_private' => 'boolean',
|
2024-06-29 18:02:23 +02:00
|
|
|
'export' => 'nullable|array',
|
2024-07-02 22:55:37 +02:00
|
|
|
'needs_prevention' => 'present|boolean',
|
2023-12-27 22:54:58 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, mixed> $attributes
|
|
|
|
*/
|
|
|
|
public function handle(array $attributes): Form
|
|
|
|
{
|
2024-04-14 00:26:17 +02:00
|
|
|
return tap(Form::create($attributes), function ($form) {
|
|
|
|
$form->setDeferredUploads(request()->input('header_image'));
|
|
|
|
$form->setDeferredUploads(request()->input('mailattachments'));
|
2024-06-10 00:17:14 +02:00
|
|
|
ClearFrontendCacheAction::run();
|
2024-04-14 00:26:17 +02:00
|
|
|
});
|
2023-12-27 22:54:58 +01:00
|
|
|
}
|
|
|
|
|
2023-12-31 21:46:52 +01:00
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function getValidationAttributes(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...$this->globalValidationAttributes(),
|
|
|
|
'from' => 'Start',
|
|
|
|
'to' => 'Ende',
|
2024-01-12 23:29:18 +01:00
|
|
|
'header_image' => 'Bild',
|
2024-02-02 01:05:45 +01:00
|
|
|
'description.blocks' => 'Beschreibung',
|
2023-12-31 21:46:52 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-12-27 22:54:58 +01:00
|
|
|
public function asController(ActionRequest $request): JsonResponse
|
|
|
|
{
|
|
|
|
$this->handle($request->validated());
|
|
|
|
|
2024-01-01 18:29:33 +01:00
|
|
|
Succeeded::message('Veranstaltung gespeichert.')->dispatch();
|
2023-12-27 22:54:58 +01:00
|
|
|
return response()->json([]);
|
|
|
|
}
|
|
|
|
}
|