laravel/framework · error · Exception
Property [{$key}] does not exist on this collection instance
Error message
Property [{$key}] does not exist on this collection instance. What it means
Thrown by Collection::__get() when accessing an undefined dynamic property. Collections expose a limited set of magic 'proxy' properties (e.g. avg, count, sum via HigherOrderCollectionProxy) listed in static::$proxies; any other property access throws. This prevents silent null returns from typos.
Source
Thrown at src/Illuminate/Collections/Traits/EnumeratesValues.php:1094
* @return void
*/
public static function proxy($method)
{
static::$proxies[] = $method;
}
/**
* Dynamically access collection proxies.
*
* @param string $key
* @return mixed
*
* @throws \Exception
*/
public function __get($key)
{
if (! in_array($key, static::$proxies)) {
throw new Exception("Property [{$key}] does not exist on this collection instance.");
}
return new HigherOrderCollectionProxy($this, $key);
}
/**
* Results array of items from Collection or Arrayable.
*
* @param mixed $items
* @return array<TKey, TValue>
*/
protected function getArrayableItems($items)
{
return is_null($items) || is_scalar($items) || $items instanceof UnitEnum
? Arr::wrap($items)
: Arr::from($items);
}
View on GitHub (pinned to bd6b5437e6)
Solutions
- Check the property name against the registered proxies; fix the typo.
- Use the method form explicitly: $collection->avg('field') instead of $collection->avg->field.
- If you intended item data, call first()/get() on the collection, not property access.
Example fix
// before
$total = $orders->totl;
// after
$total = $orders->sum('amount'); Defensive patterns
Strategy: validation
Validate before calling
$proxies = \Illuminate\Support\Collection::macrosKnownProxies(); // or check static::$proxies
if (! in_array($prop, \Illuminate\Support\Collection::$proxies, true)) {
throw new \LogicException("Unknown property $prop");
} Try / catch
try {
$value = $collection->{$prop};
} catch (\Exception $e) {
$value = null;
} Prevention
- Use the explicit method form ($c->avg('x')) instead of magic proxy properties.
- Enable IDE helper / Laravel IDE package for collection proxy auto-complete to avoid typos.
- Static-analyze to catch undefined property access.
When it happens
Trigger: Writing $collection->avrage instead of $collection->avg, or accessing $collection->first_name expecting an item property. Also $collection->total when 'total' isn't a registered proxy.
Common situations: Typos in higher-order proxy usage (e.g. $users->each->notify()). Confusing collection property access with model attribute access. IDE auto-complete suggesting a non-existent property.
Related errors
- Array value for key [%s] must be an array, %s found.
- Array value for key [%s] must be a boolean, %s found.
- Array value for key [%s] must be a float, %s found.
- Items cannot be represented by a scalar value.
- Array value for key [%s] must be an integer, %s found.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/a9bc624c9c4486c6.json.
Report an issue: GitHub.