ldc-cocotte/app/Http/Requests/Bo/PickupExceptions/StorePickupExceptionRequest.php
Jérémy Munsch b66fc01013
fix(pickup-exceptions): update repeat_frequency validation rules
Make 'repeat_frequency' nullable and conditionally required based on 'repeatable' status.
2026-10-27 09:58:20 +01:00

64 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Bo\PickupExceptions;
use Domain\Enums\RepeatFrequency;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Enum;
use Infrastructure\Adapters\Services\AppAdminAuthService;
class StorePickupExceptionRequest extends FormRequest
{
public function __construct(
private readonly AppAdminAuthService $authService
) {
}
public function authorize(): bool
{
return $this->authService->check();
}
#[\Override]
protected function prepareForValidation(): void
{
$this->merge([
'repeatable' => $this->boolean('repeatable'),
]);
}
/** @return array<string,mixed> */
public function rules(): array
{
return [
'date' => ['required', 'date_format:Y-m-d'],
'label' => ['required', 'string', 'max:255'],
'repeatable' => ['present', 'boolean:strict'],
'repeat_frequency' => ['nullable', 'required_if:repeatable,true', new Enum(RepeatFrequency::class)],
];
}
#[\Override]
protected function passedValidation(): void
{
if (! $this->boolean('repeatable')) {
$this->merge([
'repeat_frequency' => null,
]);
}
}
#[\Override]
public function attributes(): array
{
return [
'date' => trans('validation.attributes.date'),
'label' => trans('validation.custom.attributes.label'),
'repeatable' => trans('validation.custom.attributes.repeatable'),
'repeat_frequency' => trans('validation.custom.attributes.repeat_frequency'),
];
}
}