ldc-legaulois/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php
2024-06-06 11:12:12 +02:00

79 lines
2.4 KiB
PHP

<?php
namespace App\Http\Requests\Bo\StaticPages;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
class UpdateStaticPageRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('update', $this->route('static_page'));
}
/**
* Prepare the data for validation.
*
* @return void
*/
public function prepareForValidation(): void
{
$this->merge([
'content' => Str::of($this->input('content'))->value(),
'subtitle' => Str::of($this->input('subtitle'))->value(),
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$rules = [
'seo_title' => 'required|min:45|max:70',
'seo_description' => 'required|min:50|max:160',
'title' => 'required|min:3|max:255',
'subtitle' => 'present',
'content' => 'present',
'picture' => 'required',
'picture_alt' => 'required_with:picture|between:3,255',
'picture_title' => 'required_with:picture|between:3,255',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 720, 405, 720, 405),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'seo_title' => trans('validation.custom.seo_title'),
'seo_description' => trans('validation.custom.seo_description'),
'title' => trans('validation.attributes.title'),
'subtitle' => trans('validation.custom.subtitle'),
'content' => trans('validation.attributes.content'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
];
}
}