{"id":"8c427cecfe196d45","repo":"laravel/framework","slug":"call-to-undefined-method-s-s","errorCode":null,"errorMessage":"Call to undefined method %s::%s()","messagePattern":"Call to undefined method (.+?)::(.+?)\\(\\)","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/PendingHasThroughRelationship.php","lineNumber":115,"sourceCode":"        return $returnedRelation;\n    }\n\n    /**\n     * Handle dynamic method calls into the model.\n     *\n     * @param  string  $method\n     * @param  array  $parameters\n     * @return mixed\n     *\n     * @throws \\BadMethodCallException\n     */\n    public function __call($method, $parameters)\n    {\n        if (Str::startsWith($method, 'has')) {\n            return $this->has((new Stringable($method))->after('has')->lcfirst()->toString());\n        }\n\n        throw new BadMethodCallException(sprintf(\n            'Call to undefined method %s::%s()', static::class, $method\n        ));\n    }\n}\n","sourceCodeStart":97,"sourceCodeEnd":120,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/PendingHasThroughRelationship.php#L97-L120","documentation":"PendingHasThroughRelationship is a placeholder returned while defining has-one/has-many-through via the pending ->has('Relation') syntax. Its __call() magic only forwards methods starting with 'has' to has(); any other method name is undefined and throws BadMethodCallException naming the class and method.","triggerScenarios":"Chaining an arbitrary method on a pending through-relationship builder that does not start with 'has', e.g. $model->throughRelation()->someMethod() where someMethod is neither 'has' nor a has-prefixed accessor.","commonSituations":"Misunderstanding the pending relationship API and treating it as a full Builder; typos in relationship method names; calling query helpers (where, orderBy) directly on the pending object instead of the resolved relation.","solutions":["Resolve the relationship first by calling ->has('relationName') (or hasXxx) before chaining query methods.","Verify the method name you intend exists; use the camelCased distant relation name after 'has' (e.g. hasPosts()).","If you need query constraints, define them via the closure form of has(): ->has(fn ($r) => $r->where(...))."],"exampleFix":"// before\n$model->posts()->throughAuthor()->latest(); // throws\n\n// after\n$model->throughAuthor()->hasPosts()->latest();","handlingStrategy":"type-guard","validationCode":"if (! $pending instanceof \\Illuminate\\Database\\Eloquent\\PendingHasThroughRelationship\n    || ! str_starts_with($method, 'has')) {\n    throw new \\BadMethodCallException(\"Unsupported call on pending relationship: {$method}\");\n}\n$pending->{$method}();","typeGuard":"function isPendingHasCall(string $method): bool {\n    return str_starts_with($method, 'has');\n}","tryCatchPattern":"try {\n    $pending->{$method}();\n} catch (\\BadMethodCallException $e) {\n    if (str_contains($e->getMessage(), 'Call to undefined method')) {\n        // resolve relation via has() first\n    }\n    throw $e;\n}","preventionTips":["Only call has* methods on PendingHasThroughRelationship.","Resolve the relation via has('Name') before chaining query helpers.","Use the closure form of has() for query constraints."],"tags":["eloquent","relationships","has-through","magic-methods"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}