ldc-legaulois/app/Http/Requests/Bo/Subranges/StoreSubrangeRequest.php

71 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-04-12 13:41:57 +00:00
<?php
namespace App\Http\Requests\Bo\Subranges;
use App\Models\Subrange;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreSubrangeRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Gate::check('create', Subrange::class);
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'published' => $this->boolean('published'),
]);
$this->mergePicture('picture');
2024-04-12 13:41:57 +00:00
}
/**
* 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',
'picture_alt' => 'required_with:picture|nullable|between:3,255',
'picture_title' => 'required_with:picture|nullable|between:3,255',
'range_id' => 'required|exists:ranges,id',
'published' => 'required|boolean',
2024-04-12 13:41:57 +00:00
];
2026-09-25 16:25:31 +02:00
return \array_merge(
$rules,
$this->pictureRules('picture', 720, 405, 720, 405),
);
2024-04-12 13:41:57 +00:00
}
/**
* 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'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'range_id' => trans('models.classes.range'),
2026-09-25 16:25:31 +02:00
'published' => trans('validation.custom.publication'),
2024-04-12 13:41:57 +00:00
];
}
}