{"id":"8ac763d7d5727cbd","repo":"laravel/framework","slug":"property-key-does-not-exist-on-the-eloquent-b","errorCode":null,"errorMessage":"Property [{$key}] does not exist on the Eloquent builder instance.","messagePattern":"Property \\[(.+?)\\] does not exist on the Eloquent builder instance\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/Builder.php","lineNumber":2242,"sourceCode":"    /**\n     * Dynamically access builder proxies.\n     *\n     * @param  string  $key\n     * @return mixed\n     *\n     * @throws \\Exception\n     */\n    public function __get($key)\n    {\n        if (in_array($key, ['orWhere', 'whereNot', 'orWhereNot'])) {\n            return new HigherOrderBuilderProxy($this, $key);\n        }\n\n        if (in_array($key, $this->propertyPassthru)) {\n            return $this->toBase()->{$key};\n        }\n\n        throw new Exception(\"Property [{$key}] does not exist on the Eloquent builder instance.\");\n    }\n\n    /**\n     * Dynamically handle calls into the query instance.\n     *\n     * @param  string  $method\n     * @param  array  $parameters\n     * @return mixed\n     */\n    public function __call($method, $parameters)\n    {\n        if ($method === 'macro') {\n            $this->localMacros[$parameters[0]] = $parameters[1];\n\n            return;\n        }\n\n        if ($this->hasMacro($method)) {","sourceCodeStart":2224,"sourceCodeEnd":2260,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/Builder.php#L2224-L2260","documentation":"Thrown by Eloquent\\Builder::__get() when you access a property on an Eloquent query Builder that is not a recognized passthru/higher-order proxy and is not a real PHP property. The magic __get only handles 'orWhere'/'whereNot'/'orWhereNot' proxies and the small propertyPassthru list ('from'); anything else is an error.","triggerScenarios":"Doing $query->first_name, $query->email, $query->count (instead of $query->count()), or any property access on a Builder/Model::query() result expecting it to fetch a column or call a method. Also $model->relation()->someProperty.","commonSituations":"Confusing property access with method calls ($q->count vs $q->count()); assuming the builder exposes columns as properties; chaining onto a relation that returns a Builder; refactor where a Builder replaced a Model instance.","solutions":["Use the method form for builder operations: $query->count(), $query->first(), $query->get().","To access a column, fetch the model first: $query->first()->email.","Call the relation as a method and chain query methods: $user->posts()->where(...)->get().","Inspect gettype / instance check: you probably have an Eloquent\\Builder, not a Model."],"exampleFix":"// before\n$email = User::where('active', 1)->email; // __get throws\n\n// after\n$email = User::where('active', 1)->first()->email;\n// and\n$count = User::query()->count();   // method, not property","handlingStrategy":"type-guard","validationCode":"if ($builder instanceof \\Illuminate\\Database\\Eloquent\\Builder && ! in_array($key, ['orWhere','whereNot','orWhereNot','from'])) {\n    throw new \\LogicException(\"Refusing property access [$key] on Eloquent Builder; did you mean a method?\");\n}","typeGuard":"function isEloquentBuilder(mixed $v): bool {\n    return $v instanceof \\Illuminate\\Database\\Eloquent\\Builder;\n}","tryCatchPattern":null,"preventionTips":["Use methods ($q->count(), $q->first()) instead of properties on builders.","Resolve the model before accessing columns.","Static-analyze with PHPStan/Psalm to catch undefined property access on builders.","Add IDE helper annotations so the IDE knows Builder has no dynamic properties."],"tags":["eloquent","query-builder","api-misuse"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}