ldc-supportweb/app/Http/Requests/Bo/SetCellContentRequest.php
2023-08-14 09:23:39 +00:00

68 lines
1.7 KiB
PHP

<?php
namespace App\Http\Requests\Bo;
use App\Enums\Planning\CellModelEnum;
use App\Enums\Planning\CellTypeEnum;
use App\Enums\Planning\TableRowEnum;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Enum;
class SetCellContentRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
$this->merge([
'model' => $this->model ?? null,
'foreign' => $this->foreign ?? null,
'text' => $this->text ?? ''
]);
return auth()->check() and $this->ajax();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'id' => 'required|exists:week_plannings,id',
'day' => 'required|numeric',
'row' => [
'required',
new Enum(TableRowEnum::class)
],
'type' => [
'required',
new Enum(CellTypeEnum::class)
],
'CellModelEnum' => \sprintf(
'nullable',
new Enum(CellModelEnum::class)
),
'foreign' => 'required_with:CellModelEnum|nullable|numeric',
'text' => 'required|string|min:5|max:90'
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'CellModelEnum' => 'Type d\'élément lié',
'foreign' => 'Élément lié',
'text' => 'Description courte'
];
}
}