98 lines
3.9 KiB
PHP
98 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\DemarcheSlides;
|
|
|
|
use App\Models\DemarcheSlide;
|
|
use App\Rules\WysiwygLength;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreDemarcheSlideRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', DemarcheSlide::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'button_1_status' => $this->boolean('button_1_status'),
|
|
'button_1_target' => $this->boolean('button_1_target'),
|
|
'button_2_status' => $this->boolean('button_2_status'),
|
|
'button_2_target' => $this->boolean('button_2_target'),
|
|
'published' => $this->boolean('published'),
|
|
]);
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'title' => 'required|string|between:3,255',
|
|
'text' => ['required', 'string', new WysiwygLength()],
|
|
'picture_alt' => 'required_with:picture|nullable|between:3,255',
|
|
'picture_title' => 'required_with:picture|nullable|between:3,255',
|
|
'button_1_status' => 'required|boolean',
|
|
'button_1_text' => 'required_if_accepted:button_1_status|string|nullable|between:3,255',
|
|
'button_1_url' => 'required_if_accepted:button_1_status|string|nullable|url:http,https',
|
|
'button_1_target' => 'required_if_accepted:button_1_status|boolean',
|
|
'button_2_status' => 'required|boolean',
|
|
'button_2_text' => 'required_if_accepted:button_2_status|string|nullable|between:3,255',
|
|
'button_2_url' => 'required_if_accepted:button_2_status|string|nullable|url:http,https',
|
|
'button_2_target' => 'required_if_accepted:button_2_status|boolean',
|
|
'published' => 'required|boolean',
|
|
'published_at' => 'nullable|date',
|
|
'unpublished_at' => 'nullable|date|after:publish_at',
|
|
];
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', 200, 200, 200, 200),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'text' => trans('validation.attributes.text'),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
'button_1_text' => trans('validation.custom.button_text') . ' n°1',
|
|
'button_1_url' => trans('validation.custom.button_url') . ' n°1',
|
|
'button_1_status' => trans('validation.custom.button_status') . ' n°1',
|
|
'button_1_target' => trans('validation.custom.button_target') . ' n°1',
|
|
'button_2_text' => trans('validation.custom.button_text') . ' n°2',
|
|
'button_2_url' => trans('validation.custom.button_url') . ' n°2',
|
|
'button_2_status' => trans('validation.custom.button_status') . ' n°2',
|
|
'button_2_target' => trans('validation.custom.button_target') . ' n°2',
|
|
'published' => trans('validation.attributes.published'),
|
|
'published_at' => trans('validation.custom.publish_at'),
|
|
'unpublished_at' => trans('validation.custom.unpublish_at'),
|
|
];
|
|
}
|
|
}
|