2024-03-29 14:19:59 +01:00
|
|
|
<?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'),
|
2024-03-29 14:19:59 +01:00
|
|
|
]);
|
|
|
|
|
$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',
|
2024-08-01 12:24:15 +02:00
|
|
|
'source' => 'string|nullable|between:3,255',
|
2024-04-25 10:43:44 +02:00
|
|
|
'published' => 'required|boolean',
|
2024-03-29 14:19:59 +01:00
|
|
|
];
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-03-29 14:19:59 +01: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'),
|
2024-03-29 14:19:59 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|