ldc-le-gaulois-pro/app/Http/Requests/Bo/Slides/StoreSlideRequest.php
Jérémy Munsch 3a0d4e9d20
PHPstan OK
2024-02-05 09:33:08 +01:00

85 lines
2.8 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Slides;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
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(): void
{
$this->merge([
'button_display' => $this->button_display ? true : false,
'button_targetblank' => $this->button_targetblank ? true : false,
]);
$this->mergePicture('picture');
$this->mergePicture('picture_thumbnail');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'title' => 'required|min:3|max:255',
'content' => 'required|string|min:15|max:540',
'button_display' => 'required|boolean',
'button_text' => 'nullable|min:3|max:45',
'button_url' => 'nullable|min:3|max:255|url',
'button_targetblank' => 'required|boolean',
'picture_alt' => 'required|min:3|max:255',
'picture_title' => 'required|min:3|max:255',
'picture_thumbnail_alt' => 'required|min:3|max:255',
'picture_thumbnail_title' => 'required|min:3|max:255'
];
return \array_merge(
$rules,
$this->pictureRules('picture', 950, 700, 950, 700, true),
$this->pictureRules('picture_thumbnail', 167, 70, 167, 70, true)
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'title' => trans('title'),
'content' => trans('contenu de la slide'),
'button_display' => trans('afficher le bouton'),
'button_text' => trans('texte du bouton'),
'button_url' => trans('url du bouton'),
'button_targetblank' => trans('ouvrir dans un nouvel onglet'),
'picture' => trans('Illustration'),
'picture_alt' => trans('attribut alt de l\'image'),
'picture_title' => trans('titre de l\'image'),
'picture_thumbnail' => trans('vignette'),
'picture_thumbnail_alt' => trans('attribut alt de la vignette'),
'picture_thumbnail_title' => trans('titre de la vignette')
];
}
}