103 lines
2.7 KiB
PHP
103 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Bo\Slides;
|
||
|
|
|
||
|
|
use App\Traits\Requests\HasPicture;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Validation\Rules\Enum;
|
||
|
|
|
||
|
|
class StoreSlideRequest extends FormRequest
|
||
|
|
{
|
||
|
|
use HasPicture;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*
|
||
|
|
* @return boolean
|
||
|
|
*/
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return auth('backend')->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Prepare the data for validation.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
protected function prepareForValidation()
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'button_status' => $this->button_status ? true : false,
|
||
|
|
'button_new_tab' => $this->button_new_tab ? true : false
|
||
|
|
]);
|
||
|
|
if (intval($this->slider) !== \App\Enums\Slides\SliderTypeEnum::home->value()) {
|
||
|
|
$this->merge([
|
||
|
|
'video_id' => ''
|
||
|
|
]);
|
||
|
|
};
|
||
|
|
$this->mergePicture('picture');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$rules = [
|
||
|
|
'slider' => [
|
||
|
|
'required',
|
||
|
|
new Enum(\App\Enums\Slides\SliderTypeEnum::class)
|
||
|
|
],
|
||
|
|
'title' => [
|
||
|
|
'required_unless:slider,' . \App\Enums\Slides\SliderTypeEnum::home->value(),
|
||
|
|
'nullable',
|
||
|
|
'string',
|
||
|
|
'between:3,255'
|
||
|
|
],
|
||
|
|
'content' => 'required|string|between:3,255',
|
||
|
|
'video_id' => 'nullable|string|regex:%([^"&?\/\s]{11})%i',
|
||
|
|
'picture_alt' => 'required|string|between:3,255',
|
||
|
|
'picture_title' => 'required|string|between:3,255',
|
||
|
|
'button_label' => 'required_if:button_status,true|nullable|string|between:3,35',
|
||
|
|
'button_url' => 'required_if:button_status,true|nullable|string|between:3,255',
|
||
|
|
'button_status' => 'required|boolean',
|
||
|
|
'button_new_tab' => 'required|boolean',
|
||
|
|
];
|
||
|
|
return \array_merge(
|
||
|
|
$rules,
|
||
|
|
// FIXME: Mettre à jour les tailles.
|
||
|
|
$this->pictureRules('picture', 100, 100, 100, 100, null, false),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get custom attributes for validator errors.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function attributes(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
|
||
|
|
'video_id' => trans('validation.custom.video_id'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Custom validaton messages.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function messages()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'title' => [
|
||
|
|
'required_unless' => __('Le champ titre est obligatoire si le slider n\'est pas home.'),
|
||
|
|
]
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|