merge([ 'diseaseId' => $this->route('diseaseId'), 'recordId' => $this->route('recordId') ]); } public function rules(): array { return [ 'diseaseId' => 'required|integer|exists:diseases,id', 'recordId' => [ 'required', 'integer', 'exists:disease_records,id', function ($attribute, $value, $fail) { $exists = \App\Models\DiseaseRecord::where('id', $value) ->where('disease_id', $this->route('diseaseId')) ->exists(); if (!$exists) { $fail('The selected record does not belong to the specified disease.'); } }, ], ]; } protected function failedValidation(Validator $validator) { throw new HttpResponseException( ResponseJson::failedResponse('Validation error', $validator->errors()->toArray()) ); } }