ldc-legaulois/app/Http/Requests/Bo/KeyNumbers/StoreKeyNumberRequest.php

67 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Requests\Bo\KeyNumbers;
use App\Models\KeyNumber;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreKeyNumberRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Gate::check('create', KeyNumber::class);
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
2026-09-25 16:25:31 +02:00
'published' => $this->boolean('published'),
]);
$this->mergePicture('picto');
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
$rules = [
2024-04-25 10:43:44 +02:00
'text' => 'required|string|min:3',
'picto_alt' => 'required_with:picto|between:3,255',
'picto_title' => 'required_with:picto|between:3,255',
'source' => 'string|nullable|between:3,255',
2024-04-25 10:43:44 +02:00
'published' => 'required|boolean',
];
2026-09-25 16:25:31 +02:00
return \array_merge(
$rules,
$this->pictureRules('picto', 155, 155, 155, 155),
);
}
/**
* Get custom attributes for validator errors.
*/
public function attributes(): array
{
return [
2024-04-25 10:43:44 +02:00
'text' => trans('validation.attributes.text'),
'source' => trans('validation.attributes.text'),
'picto' => trans('validation.attributes.image'),
2024-05-15 12:40:31 +02:00
'picto_alt' => trans('validation.custom.attribute_alt'),
'picto_title' => trans('validation.custom.attribute_title'),
2026-09-25 16:25:31 +02:00
'published' => trans('validation.attributes.published'),
];
}
}