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

  1. Use offsetExists() (or isset($info[$key])) before reading.
  2. Use the public properties directly ($info->class, $info->table, etc.).
  3. 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

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


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): void

View on GitHub (pinned to e0f6eb3518)