99 lines
3.9 KiB
PHP
99 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Ranges;
|
|
|
|
use App\Models\Range;
|
|
use App\Rules\Hex;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreRangeRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', Range::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
]);
|
|
$this->mergePicture('banner');
|
|
$this->mergePicture('banner_ambiance');
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'label' => 'required|string|between:3,255',
|
|
'subtitle' => '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',
|
|
'picture_alt' => 'required_with:picture|nullable|between:3,255',
|
|
'picture_title' => 'required_with:picture|nullable|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),
|
|
$this->pictureRules('picture', 720, 405, 720, 405),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'label' => trans('validation.custom.label'),
|
|
'subtitle' => trans('validation.custom.subtitle'),
|
|
'description' => trans('validation.attributes.description'),
|
|
'banner_alt' => trans(':field :inter:field2', [
|
|
'field' => trans('validation.custom.attribute_alt'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom.banner'),
|
|
]),
|
|
'banner_title' => trans(':field :inter:field2', [
|
|
'field' => trans('validation.custom.attribute_title'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom.banner'),
|
|
]),
|
|
'banner_ambiance_alt' => trans(':field :inter:field2', [
|
|
'field' => trans('validation.custom.attribute_alt'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom.banner_ambiance'),
|
|
]),
|
|
'banner_ambiance_title' => trans(':field :inter:field2', [
|
|
'field' => trans('validation.custom.attribute_title'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom.banner_ambiance'),
|
|
]),
|
|
'color' => trans('validation.custom.color'),
|
|
'published' => trans('validation.custom.publication'),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
];
|
|
}
|
|
}
|