ldc-supportweb/app/Http/Requests/Back/Notices/StoreNoticeRequest.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2026-04-30 14:41:56 +02:00
<?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|min:3|max:255',
'message' => ['required', 'string', new WysiwygLength()],
'type' => ['required', 'integer', new Enum(NoticeTypeEnum::class)],
];
}
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'title' => trans('validation.custom.title'),
'message' => trans('validation.custom.message'),
'type' => trans('validation.custom.type'),
];
}
}