2022-06-02 14:45:23 +02:00
|
|
|
<?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;
|
2022-06-02 14:45:23 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
|
|
|
|
|
|
class StoreSliderRequest extends FormRequest
|
|
|
|
|
{
|
2022-07-04 10:17:34 +00:00
|
|
|
use HasPicture;
|
|
|
|
|
|
2022-06-02 14:45:23 +02:00
|
|
|
/**
|
|
|
|
|
* 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,
|
2022-06-09 09:32:59 +02:00
|
|
|
'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-06-02 14:45:23 +02:00
|
|
|
]);
|
2022-07-04 10:17:34 +00:00
|
|
|
$this->mergePicture();
|
2022-06-02 14:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
2022-07-04 10:17:34 +00:00
|
|
|
$rules = [
|
2022-06-02 14:45:23 +02:00
|
|
|
'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)],
|
2022-06-02 14:45:23 +02:00
|
|
|
'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',
|
2022-06-02 14:45:23 +02:00
|
|
|
'link_new_tab' => 'required|boolean',
|
2022-06-09 09:32:59 +02:00
|
|
|
'status' => 'required|boolean',
|
|
|
|
|
'publish_at' => 'nullable|date_format:Y-m-d H:i',
|
|
|
|
|
'unpublish_at' => 'nullable|date_format:Y-m-d H:i',
|
2022-06-02 14:45:23 +02:00
|
|
|
];
|
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));
|
2022-06-02 14:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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'),
|
2022-06-02 14:45:23 +02:00
|
|
|
'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'),
|
2022-06-02 14:45:23 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|