72 lines
2.6 KiB
PHP
72 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Timeslots;
|
|
|
|
use App\Enums\WeekDay;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateTimeslotRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return \auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'plages' => 'required|array',
|
|
'plages.*' => 'required|array',
|
|
'plages.*.morning_start' => 'nullable|required_with:plages.*.morning_end|date_format:H:i',
|
|
'plages.*.morning_end' => 'nullable|required_with:plages.*.morning_start|date_format:H:i',
|
|
'plages.*.afternoon_start' => 'nullable|required_with:plages.*.afternoon_end|date_format:H:i',
|
|
'plages.*.afternoon_end' => 'nullable|required_with:plages.*.afternoon_start|date_format:H:i',
|
|
'plages.*.interval' => [
|
|
'nullable', 'date_format:H:i',
|
|
'required_with:plages.*.morning_end',
|
|
'required_with:plages.*.morning_start',
|
|
'required_with:plages.*.afternoon_end',
|
|
'required_with:plages.*.afternoon_start',
|
|
],
|
|
'plages.*.max_orders_per_interval' => 'nullable|required_with:plages.*.interval|numeric|min:1',
|
|
'plages.*.min_order_preparation' =>
|
|
'nullable|required_with:plages.*.max_orders_per_interval|regex:/[0-9]{2}\:[0-9]{2}/',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
$attributes = [
|
|
'morning_start' => trans('Matinée Début'),
|
|
'morning_end' => trans('Matinée Début'),
|
|
'afternoon_start' => trans('Après-midi Début'),
|
|
'afternoon_end' => trans('Après-midi Fin '),
|
|
'interval' => trans('Durée d\'un crénaux'),
|
|
'max_orders_per_interval' => trans('Nb de réservations maximum par crénau'),
|
|
'min_order_preparation' => trans('Delai de préparation de commande')
|
|
];
|
|
return \collect(WeekDay::toArray())->mapWithKeys(function (WeekDay $weekDay) use ($attributes) {
|
|
return \collect($attributes)
|
|
->mapWithKeys(function (string $label, string $attribute) use ($weekDay) {
|
|
return [
|
|
"plages.{$weekDay->value}.{$attribute}" => "{$weekDay->label} : {$label}"
|
|
];
|
|
})->all();
|
|
})->all();
|
|
}
|
|
}
|