ldc-legaulois/app/Http/Requests/Bo/Ranges/StoreRangeRequest.php
2024-04-19 11:37:53 +02:00

97 lines
3.3 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Ranges;
use App\Models\Range;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use LVR\Colour\Hex;
class StoreRangeRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('create', Range::class);
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge([
'published' => $this->boolean('published'),
]);
$this->mergePicture('banner');
$this->mergePicture('banner_ambiance');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'label' => 'required|string|between:3,255',
'description' => 'required|string|min:3',
'banner_alt' => 'required|string|between:3,255',
'banner_title' => 'required|string|between:3,255',
'banner_ambiance_alt' => 'required|string|between:3,255',
'banner_ambiance_title' => 'required|string|between:3,255',
'color' => ['required', new Hex()],
'published' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('banner', 700, 350, 700, 350, false),
$this->pictureRules('banner_ambiance', 1440, 420, 1440, 420, false),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'label' => trans('validation.custom.label'),
'description' => trans('validation.attributes.description'),
'banner_alt' => trans(':field :inter:field2', [
'field' => __('validation.custom.attribute_alt'),
'inter' => __('validation.custom.of_the.female'),
'field2' => __('validation.custom.banner'),
]),
'banner_title' => trans(':field :inter:field2', [
'field' => __('validation.custom.attribute_title'),
'inter' => __('validation.custom.of_the.female'),
'field2' => __('validation.custom.banner'),
]),
'banner_ambiance_alt' => trans(':field :inter:field2', [
'field' => __('validation.custom.attribute_alt'),
'inter' => __('validation.custom.of_the.female'),
'field2' => __('validation.custom.banner_ambiance'),
]),
'banner_ambiance_title' => trans(':field :inter:field2', [
'field' => __('validation.custom.attribute_title'),
'inter' => __('validation.custom.of_the.female'),
'field2' => __('validation.custom.banner_ambiance'),
]),
'color' => trans('validation.custom.color'),
'published' => trans('validation.custom.publication')
];
}
}