111 lines
3.8 KiB
PHP
111 lines
3.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Bo\Slides;
|
||
|
|
|
||
|
|
use App\Traits\Requests\HasPicture;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Support\Facades\Date;
|
||
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||
|
|
|
||
|
|
class StoreSlideRequest extends FormRequest
|
||
|
|
{
|
||
|
|
use HasPicture;
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
private readonly AppAdminAuthService $authService
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return $this->authService->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
protected function prepareForValidation(): void
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'connected' => $this->boolean('connected'),
|
||
|
|
'link_new_tab' => $this->boolean('link_new_tab'),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return array<string,mixed> */
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$maxWidth = 1440;
|
||
|
|
$maxHeight = 960;
|
||
|
|
|
||
|
|
return array_merge(
|
||
|
|
[
|
||
|
|
'title' => ['required', 'string', 'min:4', 'max:75'],
|
||
|
|
'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||
|
|
'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||
|
|
'text' => ['required_without:picture', 'string', 'min:5'],
|
||
|
|
'link' => ['nullable', 'url:https', 'max:255'],
|
||
|
|
'link_label' => ['nullable', 'string', 'min:5', 'max:255'],
|
||
|
|
'link_new_tab' => ['present', 'boolean:strict'],
|
||
|
|
'connected' => ['present', 'boolean:strict'],
|
||
|
|
'date_start' => ['nullable', 'date_format:Y-m-d\TH:i'],
|
||
|
|
'date_end' => ['nullable', 'date_format:Y-m-d\TH:i', 'after:date_start'],
|
||
|
|
'client_timezone' => ['required', 'timezone'],
|
||
|
|
],
|
||
|
|
$this->pictureRules(
|
||
|
|
'picture',
|
||
|
|
$maxWidth,
|
||
|
|
$maxHeight,
|
||
|
|
$maxWidth,
|
||
|
|
$maxHeight,
|
||
|
|
true
|
||
|
|
)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
protected function passedValidation()
|
||
|
|
{
|
||
|
|
if ($this->filled('date_start')) {
|
||
|
|
$inputValue = Date::createFromFormat(
|
||
|
|
'Y-m-d\TH:i',
|
||
|
|
$this->string('date_start')->value(),
|
||
|
|
$this->string('client_timezone')->value()
|
||
|
|
)?->setTimezone('UTC');
|
||
|
|
|
||
|
|
$this->merge([
|
||
|
|
'date_start' => $inputValue?->format('Y-m-d H:i:s'),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
if ($this->filled('date_end')) {
|
||
|
|
$inputValue = Date::createFromFormat(
|
||
|
|
'Y-m-d\TH:i',
|
||
|
|
$this->string('date_end')->value(),
|
||
|
|
$this->string('client_timezone')->value()
|
||
|
|
)?->setTimezone('UTC');
|
||
|
|
|
||
|
|
$this->merge([
|
||
|
|
'date_end' => $inputValue?->format('Y-m-d H:i:s'),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
public function attributes(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'title' => trans('validation.attributes.title'),
|
||
|
|
'text' => trans('validation.attributes.text'),
|
||
|
|
'date_start' => trans('validation.custom.attributes.date_start_show'),
|
||
|
|
'date_end' => trans('validation.custom.attributes.date_end_show'),
|
||
|
|
'connected' => trans('validation.custom.attributes.connected'),
|
||
|
|
'link' => trans('validation.custom.attributes.link'),
|
||
|
|
'link_label' => trans('validation.custom.attributes.link_label'),
|
||
|
|
'link_new_tab' => trans('validation.custom.attributes.link_new_tab'),
|
||
|
|
'picture' => trans('validation.attributes.image'),
|
||
|
|
'picture_alt' => trans('validation.custom.attributes.picture_alt'),
|
||
|
|
'picture_title' => trans('validation.custom.attributes.picture_title'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|