laravel/framework · error · InvalidArgumentException
Property does not exist.
Error message
Property {$offset} does not exist. What it means
ModelInfo is a read-only value object exposing model metadata (class, database, table, policy, attributes, relations, events, observers, collection, builder, resource). offsetGet throws when you array-access a property name that is not one of those declared properties. It is constructed by the framework (e.g. for debugging/inspection) and not meant to carry arbitrary keys.
Solutions
- Use offsetExists() (or isset($info[$key])) before reading.
- Use the public properties directly ($info->class, $info->table, etc.).
- Limit access to the known set of keys defined on the class.
Example fix
// before
$name = $info['missspelled']; // throws
// after
if (isset($info['class'])) {
$name = $info['class'];
}
// or use the property
$name = $info->class; Defensive patterns
Strategy: type-guard
Validate before calling
// ModelInfo exposes a fixed set of properties $allowed = ['class','database','table','policy','attributes','relations','events','observers','collection','builder','resource']; $value = in_array($key, $allowed, true) ? $info[$key] : null;
Type guard
function modelInfoHas(\Illuminate\Database\Eloquent\ModelInfo $info, string $key): bool {
return $info->offsetExists($key);
} Try / catch
try {
$v = $info[$key];
} catch (\InvalidArgumentException $e) {
if (str_contains($e->getMessage(), 'does not exist')) {
$v = null;
} else { throw $e; }
} Prevention
- Use the public properties ($info->class, $info->table) instead of array access when the key is known.
- Always guard array access with isset($info[$key]) / offsetExists.
- Treat ModelInfo as a fixed schema value object.
When it happens
Trigger: Calling $info['nonexistent'] where $info is a ModelInfo instance and the key is not class/database/table/policy/attributes/relations/events/observers/collection/builder/resource.
Common situations: Iterating or destructuring ModelInfo assuming it has request-driven keys; typos in the offset; code that inspects all keys via array access and hits an optional like 'policy'.
Related errors
- may not be mutated using array access.
- Add fillable property
- Add [ ] to fillable property to allow mass assignment on […
- Call to undefined cast
- Call to undefined method
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/26885581b3827216.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Database/Eloquent/ModelInfo.php:95
];
}
/**
* Determine if the given offset exists.
*/
public function offsetExists(mixed $offset): bool
{
return property_exists($this, $offset);
}
/**
* Get the value for a given offset.
*
* @throws \InvalidArgumentException
*/
public function offsetGet(mixed $offset): mixed
{
return property_exists($this, $offset) ? $this->{$offset} : throw new InvalidArgumentException("Property {$offset} does not exist.");
}
/**
* Set the value at the given offset.
*
* @throws \LogicException
*/
public function offsetSet(mixed $offset, mixed $value): void
{
throw new LogicException(self::class.' may not be mutated using array access.');
}
/**
* Unset the value at the given offset.
*
* @throws \LogicException
*/
public function offsetUnset(mixed $offset): voidView on GitHub (pinned to e0f6eb3518)