68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\Planning\CellModel;
|
|
use App\Enums\Planning\CellType;
|
|
use App\Enums\Planning\TableRow;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
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 EnumIsValidRule(TableRow::class)
|
|
],
|
|
'type' => [
|
|
'required',
|
|
new EnumIsValidRule(CellType::class)
|
|
],
|
|
'cellModel' => \sprintf(
|
|
'nullable',
|
|
new EnumIsValidRule(CellModel::class)
|
|
),
|
|
'foreign' => 'required_with:cellModel|nullable|numeric',
|
|
'text' => 'required|string|min:5|max:90'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'cellModel' => 'Type d\'élément lié',
|
|
'foreign' => 'Élément lié',
|
|
'text' => 'Description courte'
|
|
];
|
|
}
|
|
}
|