laravel/framework · error · Exception
Property [{$key}] does not exist on the Eloquent builder ins
Error message
Property [{$key}] does not exist on the Eloquent builder instance. What it means
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.
Source
Thrown at src/Illuminate/Database/Eloquent/Builder.php:2242
/**
* Dynamically access builder proxies.
*
* @param string $key
* @return mixed
*
* @throws \Exception
*/
public function __get($key)
{
if (in_array($key, ['orWhere', 'whereNot', 'orWhereNot'])) {
return new HigherOrderBuilderProxy($this, $key);
}
if (in_array($key, $this->propertyPassthru)) {
return $this->toBase()->{$key};
}
throw new Exception("Property [{$key}] does not exist on the Eloquent builder instance.");
}
/**
* Dynamically handle calls into the query instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
if ($method === 'macro') {
$this->localMacros[$parameters[0]] = $parameters[1];
return;
}
if ($this->hasMacro($method)) {View on GitHub (pinned to bd6b5437e6)
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.
Example fix
// before
$email = User::where('active', 1)->email; // __get throws
// after
$email = User::where('active', 1)->first()->email;
// and
$count = User::query()->count(); // method, not property Defensive patterns
Strategy: type-guard
Validate before calling
if ($builder instanceof \Illuminate\Database\Eloquent\Builder && ! in_array($key, ['orWhere','whereNot','orWhereNot','from'])) {
throw new \LogicException("Refusing property access [$key] on Eloquent Builder; did you mean a method?");
} Type guard
function isEloquentBuilder(mixed $v): bool {
return $v instanceof \Illuminate\Database\Eloquent\Builder;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The chunkById operation was aborted because the [{$alias}] c
- No record found for the given query.
- $count records were found.
- Unable to create query for empty collection.
- Unable to create query for collection with mixed types.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/8ac763d7d5727cbd.json.
Report an issue: GitHub.