ldc-le-gaulois-pro/app/Http/Requests/Bo/BrigadeSections/StoreBrigadeSectionsRequest.php
2026-02-05 12:26:20 +01:00

84 lines
2.4 KiB
PHP

<?php
namespace App\Http\Requests\Bo\BrigadeSections;
use App\Rules\WysiwygLength;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
class StoreBrigadeSectionsRequest 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(): void
{
$this->merge([
'published' => $this->boolean('published'),
'button_display' => $this->boolean('button_display'),
'button_newtab' => $this->boolean('button_newtab'),
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'title' => 'required|string|min:3|max:500',
'content' => [
'required',
'string',
new WysiwygLength(15, 1500)
],
'picture_alt' => 'required|string|min:3|max:255',
'picture_title' => 'required|string|min:3|max:255',
'button_display' => 'required|boolean',
'button_text' => 'required_if_accepted:button_display|nullable|string|min:3|max:255',
'button_url' => 'required_if_accepted:button_display|nullable|url:https|min:3|max:255',
'button_newtab' => 'required|boolean',
'published' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 800, 535, 800, 535, false),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'title' => trans('Titre'),
'picture' => trans('Image'),
'picture_alt' => trans('Attribut alt de l\'image'),
'picture_title' => trans('Titre de l\'image'),
'content' => trans('Contenu'),
'button_text' => trans('Texte du CTA'),
'button_url' => trans('URL du CTA'),
'published' => trans('Statut'),
];
}
}