ldc-supportweb/app/Http/Requests/Back/Notices/StoreNoticeRequest.php
2026-05-28 10:50:21 +02:00

55 lines
1.4 KiB
PHP

<?php
namespace App\Http\Requests\Back\Notices;
use App\Enums\NoticeTypeEnum;
use App\Models\Notice;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\Enum;
use Uwil\LaravelBackend\Rules\WysiwygLength;
/**
* Handles authorization and validation for creating a new Notice.
*/
class StoreNoticeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('create', Notice::class);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'title' => 'required|string|between:3,255',
'message' => ['required', 'string', new WysiwygLength()],
'type' => ['required', 'integer', new Enum(NoticeTypeEnum::class)],
];
}
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
#[\Override]
public function attributes(): array
{
return [
'title' => trans('validation.custom.title'),
'message' => trans('validation.custom.message'),
'type' => trans('validation.custom.type'),
];
}
}