check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation(): void { $this->orderable = collect($this->route()->parameters()) ->first(fn($param) => $param instanceof Model); $groupField = $this->orderable->getOrderGroupField(); if ($groupField) { $this->orderable::query()->where($groupField, $this->orderable->{$groupField}); } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'priority_order' => [ 'required', 'integer', 'min:1', sprintf('max:%s', $this->orderable->max('priority_order')), function ($value, $fail) { // phpcs:ignore Generic.Files.LineLength.TooLong if ($this->orderable instanceof OrderableInterface && intval($value) === $this->orderable->getPriorityOrder()) { $fail(trans('validation.custom.same_priority')); } }, ], ]; } }