laravel/framework · error · EntryNotFoundException

{$id}

Error message

{$id}

What it means

EntryNotFoundException thrown by the PSR-11 Container::get($id) when $id is neither bound/resolvable in the container and resolution raised an Exception that is not a CircularDependencyException. get() re-throws original errors only when the entry is known to exist (has($id) true); otherwise it wraps the cause in EntryNotFoundException to comply with PSR-11.

Source

Thrown at src/Illuminate/Container/Container.php:888

     *
     * @template TClass of object
     *
     * @param  string|class-string<TClass>  $id
     * @return ($id is class-string<TClass> ? TClass : mixed)
     *
     * @throws \Illuminate\Contracts\Container\CircularDependencyException
     * @throws \Illuminate\Container\EntryNotFoundException
     */
    public function get(string $id)
    {
        try {
            return $this->resolve($id);
        } catch (Exception $e) {
            if ($this->has($id) || $e instanceof CircularDependencyException) {
                throw $e;
            }

            throw new EntryNotFoundException($id, is_int($e->getCode()) ? $e->getCode() : 0, $e);
        }
    }

    /**
     * Resolve the given type from the container.
     *
     * @template TClass of object
     *
     * @param  string|class-string<TClass>|callable  $abstract
     * @param  array  $parameters
     * @param  bool  $raiseEvents
     * @return ($abstract is class-string<TClass> ? TClass : mixed)
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Illuminate\Contracts\Container\CircularDependencyException
     */
    protected function resolve($abstract, $parameters = [], $raiseEvents = true)
    {

View on GitHub (pinned to e0f6eb3518)

Solutions

  1. Verify the id is bound: if ($container->has($id)) before calling get().
  2. Register the missing binding in a service provider or confirm the provider is in config/app.php.
  3. Switch to make() if you want autowiring of class strings rather than strict PSR-11 lookup.
  4. Check the previous exception ($e->getPrevious()) for the underlying cause of the resolution failure.

Example fix

// before
$svc = $container->get('billing.gateway');
// after
if (! $container->has('billing.gateway')) {
    throw new RuntimeException('billing.gateway not registered');
}
$svc = $container->get('billing.gateway');
Defensive patterns

Strategy: validation

Validate before calling

// PSR-11 safe lookup
$id = 'billing.gateway';
if (! $container->has($id)) {
    throw new RuntimeException("Service [$id] is not registered in the container.");
}
$service = $container->get($id);

Type guard

// Use has() as the narrowing guard before get().
assert($container->has($id));
$service = $container->get($id);

Try / catch

use Illuminate\Container\EntryNotFoundException;

try {
    $service = $container->get($id);
} catch (EntryNotFoundException $e) {
    // inspect $e->getPrevious() for the real cause; register the binding or fix the id
    throw $e;
}

Prevention

When it happens

Trigger: Calling $container->get('some-service-key') for a string key that was never bound; resolving a class string whose constructor dependencies cannot be satisfied and the class is not registered.

Common situations: Using PSR-11 get() with a service id from config that is misnamed or removed after a refactor; environment difference where a provider is registered in dev but not production; accessing a deferred-provider service before the provider loaded.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/7045106897627337. Report an issue: GitHub.