ldc-volena/app/Http/Requests/Bo/Strips/StoreStripRequest.php
2026-04-24 15:06:55 +02:00

101 lines
2.9 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Strips;
use App\Rules\WysiwygLength;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Enum;
class StoreStripRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge([
'published' => $this->boolean('published'),
]);
if ($this->input('picture')) {
$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 = [
'text' => [
'required',
'string',
new WysiwygLength(3, 90),
],
'news_id' => 'nullable|exists:news,id',
'published' => 'required|boolean',
'publish_at' => 'nullable|date',
'unpublish_at' => 'nullable|date|after:publish_at',
];
if ($this->input('picture')) {
$rules = array_merge(
$rules,
[
'picture_alt' => 'required_with|string|between:3,255',
'picture_title' => 'required_with|string|between:3,255',
],
$this->pictureRules('picture', 100, 65, 100, 65, true),
);
} else {
$rules = array_merge(
$rules,
[
'picto' => [
'required',
new Enum(\App\Enums\Strips\PictoEnum::class)
],
],
);
}
return $rules;
}
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'picto' => trans('validation.custom.picto'),
'picture' => trans('validation.custom.picture'),
'picture_alt' => trans('validation.custom.alt_attribute'),
'picture_title' => trans('validation.custom.title_attribute'),
'text' => trans('validation.attributes.content'),
'news_id' => trans('models.classes.news'),
'published' => trans('validation.custom.activated'),
'publish_at' => trans('validation.custom.publish_at'),
'unpublish_at' => trans('validation.custom.unpublish_at'),
];
}
}