ldc-lionor/app/Http/Requests/Bo/Ranges/UpdateRangeRequest.php

91 lines
2.7 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Ranges;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class UpdateRangeRequest 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([
'slug' => Str::slug(strip_tags($this->name)),
'status' => $this->status ? true : false
]);
$this->mergePicture('picture');
$this->mergePicture('banner');
$this->mergePicture('sticker');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'name' => 'required|min:3|max:255',
'subtitle' => 'nullable|max:255',
'seo_title' => 'required|min:45|max:70',
'seo_description' => 'required|min:50|max:160',
'picture_alt' => 'required|min:3|max:255',
'picture_title' => 'required|min:3|max:255',
'banner_alt' => 'required|min:3|max:255',
'banner_title' => 'required|min:3|max:255',
'sticker_alt' => 'required|min:3|max:255',
'sticker_title' => 'required|min:3|max:255',
'status' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('banner', 1600, 312, 1600, 312, true),
$this->pictureRules('picture', 650, 415, 650, 415, true),
$this->pictureRules('sticker', 340, 270, 340, 270, true),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'name' => trans('nom'),
'slug' => trans('slug'),
'seo_title' => trans('title') . ' seo',
'seo_description' => trans('description') . ' seo',
'picture' => trans('Illustration'),
'picture_alt' => trans('attribut alt de l\'image'),
'picture_title' => trans('titre de l\'image'),
'banner' => trans('bannière'),
'banner_alt' => trans('attribut alt de la bannière'),
'banner_title' => trans('titre de la bannière'),
'sticker' => trans('vignette'),
'sticker_alt' => trans('attribut alt de la vignette'),
'sticker_title' => trans('titre de la vignette'),
'status' => trans('état de publication'),
];
}
}