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', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function ($attribute, $value, $fail) { if ($this->orderable && intval($value) < 1) { $fail(trans('validation.custom.min_priority')); } }, sprintf('max:%s', $this->orderable->max('priority_order')), // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function ($attribute, $value, $fail) { if ($this->orderable && intval($value) === $this->orderable->priority_order) { $fail(trans('validation.custom.same_priority')); } }, ], ]; } }