73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?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.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', KeyNumber::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published')
|
|
]);
|
|
$this->mergePicture('picto');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'text' => 'required|string|min:3',
|
|
'picto_alt' => 'required_with:picto|between:3,255',
|
|
'picto_title' => 'required_with:picto|between:3,255',
|
|
'source' => 'sometimes|string|nullable|between:3,255',
|
|
'published' => 'required|boolean',
|
|
];
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picto', 155, 155, 155, 155),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'text' => trans('validation.attributes.text'),
|
|
'source' => trans('validation.attributes.text'),
|
|
'picto' => trans('validation.attributes.image'),
|
|
'picto_alt' => trans('validation.attributes.alt_attribute'),
|
|
'picto_title' => trans('validation.attributes.title_attribute'),
|
|
'published' => trans('validation.attributes.published')
|
|
];
|
|
}
|
|
}
|