laravel/framework · warning · LogicException
%s may not be mutated using array access.
Error message
%s may not be mutated using array access.
What it means
ModelInfo is intentionally immutable: it is a snapshot of introspection data, so offsetSet() unconditionally throws LogicException to prevent mutation. There is no path that allows writing via array syntax.
Source
Thrown at src/Illuminate/Database/Eloquent/ModelInfo.php:105
/**
* 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): void
{
throw new LogicException(self::class.' may not be mutated using array access.');
}
}
View on GitHub (pinned to bd6b5437e6)
Solutions
- Do not mutate ModelInfo; build a new value or modify the underlying model/schema instead.
- If you need a mutable copy, work with $info->toArray() and change the resulting array.
- Refactor generic ArrayAccess consumers to skip write operations for read-only objects.
Example fix
// before $info['table'] = 'users'; // throws // after $data = $info->toArray(); $data['table'] = 'users';
Defensive patterns
Strategy: type-guard
Validate before calling
// ModelInfo is immutable; copy to array before mutating $data = $info->toArray(); $data[$key] = $value;
Type guard
function isMutable(ArrayAccess $obj): bool {
return ! ($obj instanceof \Illuminate\Database\Eloquent\ModelInfo);
} Prevention
- Never write to ModelInfo via array syntax.
- Mutate a toArray() copy instead.
- Skip write operations in generic ArrayAccess consumers for read-only DTOs.
When it happens
Trigger: Attempting $info['table'] = 'new_table' or any $info[...] = value assignment on a ModelInfo instance.
Common situations: Treating ModelInfo like a regular model or array; code written generically against ArrayAccess that tries to write.
Related errors
- Property {$offset} does not exist.
- The chunkById operation was aborted because the [{$alias}] c
- The lazyById operation was aborted because the [{$alias}] co
- No record found for the given query.
- $count records were found.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/d5019afdb88712de.json.
Report an issue: GitHub.