{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/PendingHasThroughRelationship.php#L97-L120","documentation":"PendingHasThroughRelationship is the intermediate object returned by the has?Through style 'through()' helper. Its __call magic only forwards methods starting with 'has' (e.g. hasPosts) to has(); any other method call is treated as undefined and throws BadMethodCallException. This surfaces typos and wrong chaining in has-one/has-many-through definitions.","triggerScenarios":"Writing return $this->through($relation)->someOtherMethod(...) where someOtherMethod does not start with 'has', or chaining a non-has method onto the result of through().","commonSituations":"Misremembering the fluent API for has-through; copy-paste from a normal relation definition; IDE autocomplete suggesting a wrong method; typo like 'thas' instead of 'has'.","solutions":["Use the has() method (or a has-prefixed dynamic method) on the pending object: $this->through($relation)->has('comments').","Verify the distant relationship callback you intend to call actually maps to a 'has' method.","Re-read the PendingHasThroughRelationship API to confirm the only dynamic surface is has*."],"exampleFix":"// before\nreturn $this->through($local)->comments(); // throws\n\n// after\nreturn $this->through($local)->has('comments');\n// or via the dynamic 'has' prefix\nreturn $this->through($local)->hasComments();","handlingStrategy":"validation","validationCode":"// Only methods beginning with 'has' are valid on a PendingHasThroughRelationship\nif (! str_starts_with($method, 'has')) {\n    throw new \\BadMethodCallException(\"Only has* methods are valid on PendingHasThroughRelationship, got: {$method}\");\n}\nreturn $this->through($local)->{$method}(...$args);","typeGuard":"function isValidHasThroughCall(string $method): bool {\n    return str_starts_with($method, 'has');\n}","tryCatchPattern":null,"preventionTips":["Always terminate a through() chain with has() (or a has* dynamic method).","Re-read PendingHasThroughRelationship - the only dynamic surface is has*.","If you need other behaviour, define the relationship with hasManyThrough/hasOneThrough directly."],"tags":["eloquent","relationships","has-through","bad-method-call","dynamic-calls"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}