|string> */ public function rules(): array { return [ 'user_id' => ['nullable', Rule::exists('users', 'id')->where('level', UserEnum::Doctor->value)], 'day_of_week' => ['nullable', 'required_without:date', 'string', Rule::in(ShiftDayEnum::values())], 'date' => ['nullable', 'required_without:day_of_week', 'date'], 'start_time' => ['required', 'date_format:H:i'], 'end_time' => ['required', 'date_format:H:i', 'different:start_time'], 'is_active' => ['required', 'boolean'], ]; } public function prepareForValidation() { if ($this->filled('date')) { $this->merge(['day_of_week' => null]); } } public function withValidator(Validator $validator): void { $validator->after(function (Validator $validator) { if ($validator->errors()->isNotEmpty()) { return; } $scheduleService = app(ShiftScheduleService::class); $ignoreId = $this->route('shift')?->id; if ($scheduleService->hasConflict($this->validated(), $ignoreId)) { $validator->errors()->add('start_time', 'این شیفت با شیفت دیگری از این پزشک تداخل دارد.'); } }); } }