ldc-le-gaulois-pro/app/Http/Requests/Bo/Slides/StoreSlideRequest.php
2022-12-15 16:35:06 +00:00

84 lines
2.5 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()
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$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()
{
$rules = [
'title' => 'required|min:3|max:255',
'content' => 'required|min:3|max:255',
'button_display' => 'required|boolean',
'button_text' => 'nullable|min:3|max:45',
'button_url' => 'nullable|min:3|max:255',
'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', true, 950, 700, 950, 700),
$this->pictureRules('picture_thumbnail', true, 167, 70, 167, 70)
);
}
/**
* 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('image'),
'picture_alt' => trans('attribut alt de l\'image'),
'picture_title' => trans('titre de l\'image'),
'picture_thumbnail_alt' => trans('attribut alt de la vignette'),
'picture_thumbnail_title' => trans('titre de la vignette')
];
}
}