90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Sliders;
|
|
|
|
use App\Enums\Sliders\SliderPosition;
|
|
use App\Enums\Sliders\SliderType;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
class StoreSliderRequest extends FormRequest
|
|
{
|
|
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,
|
|
]);
|
|
$this->mergePicture();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return \array_merge([
|
|
'title' => 'required|min:3|max:255',
|
|
'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',
|
|
'type' => ['required', new EnumIsValidRule(SliderType::class)],
|
|
'position' => ['required', new EnumIsValidRule(SliderPosition::class)],
|
|
'link' => 'required|url',
|
|
'link_title' => 'required|min:3|max:255',
|
|
'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',
|
|
], $this->pictureRules(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'),
|
|
'position' => trans('position de centrage de l\'image'),
|
|
'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'),
|
|
];
|
|
}
|
|
}
|