ldc-volena/app/Http/Requests/Bo/Strips/StoreStripRequest.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2023-11-27 11:55:37 +01:00
<?php
namespace App\Http\Requests\Bo\Strips;
use App\Rules\WysiwygLength;
2023-11-27 11:55:37 +01:00
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
*/
2024-03-20 17:39:24 +01:00
protected function prepareForValidation(): void
2023-11-27 11:55:37 +01:00
{
$this->merge([
'published' => $this->boolean('published'),
2023-11-27 11:55:37 +01:00
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'picto' => [
'required',
new Enum(\App\Enums\Strips\PictoEnum::class)
],
'text' => [
'required',
'string',
new WysiwygLength(3, 90),
2023-11-27 11:55:37 +01:00
],
'news_id' => 'nullable|exists:news,id',
'published' => 'required|boolean',
'publish_at' => 'nullable|date',
'unpublish_at' => 'nullable|date|after:publish_at',
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
2024-03-20 17:39:24 +01:00
'picto' => trans('validation.custom.picto'),
'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'),
2023-11-27 11:55:37 +01:00
];
}
}