ldc-loue/app/Http/Requests/Bo/Sliders/StoreSliderRequest.php

98 lines
3.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests\Bo\Sliders;
2022-07-04 10:17:34 +00:00
use App\Enums\Sliders\SliderElementPosition;
use App\Enums\Sliders\SliderType;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
class StoreSliderRequest extends FormRequest
{
2022-07-04 10:17:34 +00:00
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'link_new_tab' => $this->link_new_tab ? true : false,
'status' => $this->status ? true : false,
'publish_at' => $this->publish_at ? \str_replace('T', ' ', $this->publish_at) : null,
'unpublish_at' => $this->unpublish_at ? \str_replace('T', ' ', $this->unpublish_at) : null,
]);
2022-07-04 10:17:34 +00:00
$this->mergePicture();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2022-07-04 10:17:34 +00:00
$rules = [
'title' => 'required|min:3|max:255',
2022-07-04 10:17:34 +00:00
'title_color' => 'nullable|color_rgba',
'title_color_bg' => 'nullable|color_rgba',
'subtitle' => 'required|min:3|max:255',
'subtitle_color' => 'nullable|color_rgba',
'subtitle_color_bg' => 'nullable|color_rgba',
'text_position_desktop' => ['required', new EnumIsValidRule(SliderElementPosition::class)],
'picture_position_mobile' => ['required', new EnumIsValidRule(SliderElementPosition::class)],
'link' => 'required|url',
'link_title' => 'required|min:3|max:255',
2022-07-04 10:17:34 +00:00
'link_color' => 'nullable|color_rgba',
'link_color_hover' => 'nullable|color_rgba',
'link_color_bg' => 'nullable|color_rgba',
'link_color_bg_hover' => 'nullable|color_rgba',
'link_new_tab' => 'required|boolean',
'status' => 'required|boolean',
'publish_at' => 'nullable|date_format:Y-m-d H:i',
'unpublish_at' => 'nullable|date_format:Y-m-d H:i',
];
2022-07-04 10:17:34 +00:00
if (!$this->slider) {
$rules['type'] = ['required', new EnumIsValidRule(SliderType::class)];
}
2022-11-07 17:12:56 +01:00
return \array_merge($rules, $this->pictureRules('picture', 1400, 630, 1400, 630));
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'title' => trans('title'),
'title_color' => trans('couleur de titre'),
'title_color_bg' => trans('couleur de fond du titre'),
2022-07-04 10:17:34 +00:00
'picture_position_mobile' => trans('position de centrage de l\'image en mobile'),
'text_position_desktop' => trans('position de centrage du texte en desktop'),
'link' => trans('lien'),
'link_title' => trans('titre du lien'),
'link_color' => trans('couleur du lien'),
'link_color_bg' => trans('couleur de fond du lien'),
'link_new_tab' => trans('nouvel onglet'),
'status' => trans('publication'),
2022-07-04 10:17:34 +00:00
'picture' => trans('image'),
];
}
}