ldc-supportweb/app/Http/Requests/SetCellContentRequest.php
2022-03-29 16:57:54 +02:00

63 lines
1.6 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()
{
$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()
{
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'
];
}
public function attributes()
{
return [
'cellModel' => 'Type d\'élément lié',
'foreign' => 'Élément lié',
'text' => 'Description courte'
];
}
}