ldc-le-gaulois-pro/app/Http/Requests/Bo/Ranges/UpdateRangeRequest.php

83 lines
2.5 KiB
PHP
Raw Normal View History

2022-12-12 17:24:53 +01:00
<?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(): bool
2022-12-12 17:24:53 +01:00
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
2022-12-12 17:24:53 +01:00
{
$this->merge([
'slug' => Str::slug(strip_tags($this->label))
2022-12-12 17:24:53 +01:00
]);
$this->mergePicture('picture');
$this->mergePicture('picture_banner');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
2022-12-12 17:24:53 +01:00
{
$rules = [
'label' => 'required|min:3|max:255',
'seo_title' => 'required|min:45|max:70',
'seo_description' => 'required|min:50|max:160',
'color' => 'required|color_rgba',
'picture_alt' => 'required|min:3|max:255',
'picture_title' => 'required|min:3|max:255',
'picture_banner_alt' => 'required|min:3|max:255',
2022-12-12 17:24:53 +01:00
'picture_banner_title' => 'required|min:3|max:255',
];
return \array_merge(
$rules,
2024-02-05 09:33:08 +01:00
$this->pictureRules('picture', 290, 232, 290, 232, true),
$this->pictureRules('picture_banner', 1440, 300, 1440, 300, true),
2022-12-12 17:24:53 +01:00
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'label' => trans('label'),
'slug' => trans('slug'),
'seo_title' => trans('title') . ' seo',
'seo_description' => trans('description') . ' seo',
'color' => trans('couleur'),
'picture' => trans('Illustration'),
'picture_alt' => trans('attribut alt de l\'image'),
'picture_title' => trans('titre de l\'image'),
'picture_banner' => trans('bannière'),
'picture_banner_alt' => trans('attribut alt de la bannière'),
2022-12-12 17:24:53 +01:00
'picture_banner_title' => trans('titre de la bannière'),
];
}
}