ldc-legaulois/app/Http/Requests/Bo/Testimonials/StoreTestimonialRequest.php
2026-09-25 16:25:31 +02:00

83 lines
2.5 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Testimonials;
use App\Models\Testimonial;
use App\Rules\IsValidYoutubeId;
use App\Rules\WysiwygLength;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreTestimonialRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Gate::check('create', Testimonial::class);
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'published' => $this->boolean('published'),
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
$rules = [
'catchline' => 'required|string|between:3,255',
'content' => [
'required',
'string',
new WysiwygLength(max: 600),
],
'identity' => 'required|string|between:3,255',
'job' => 'required|string|between:3,255',
'picture_alt' => 'required|string|between:3,255',
'picture_title' => 'required|string|between:3,255',
'video_id' => [
'nullable',
new IsValidYoutubeId(),
],
'published' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 550, 315, 550, 315),
);
}
/**
* Get custom attributes for validator errors.
*/
public function attributes(): array
{
return [
'catchline' => trans_choice('validation.custom.catchline', 1),
'content' => trans('validation.attributes.content'),
'identity' => trans('validation.custom.identity'),
'job' => trans('validation.custom.job'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'video_id' => trans('validation.custom.youtube_video_id'),
'published' => trans('validation.custom.publication'),
];
}
}