roemer
745
1
Laravel

'Illegal offset type in isset or empty' in Container for service provider

Posted 2 years ago by roemer

Hi,

I have a service provider which registers a bunch of singletons like so:

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $services = array(
            'App\Contracts\Repositories\RealworksRepository'    => 'App\Repositories\RealworksRepository',
            'App\Contracts\Repositories\PropertyRepository'     => 'App\Repositories\PropertyRepository',
            'App\Contracts\Repositories\SlideRepository'        => 'App\Repositories\SlideRepository'
        );

        foreach($services as $contract => $service)
        {
            $this->app->singleton($contract, $services);
        }
    }

But I'm getting the following error:

ErrorException in Container.php line 1093:
Illegal offset type in isset or empty
in Container.php line 1093
at HandleExceptions->handleError('2', 'Illegal offset type in isset or empty', '/home/vagrant/Code/makelaarstvcom/vendor/laravel/framework/src/Illuminate/Container/Container.php', '1093', array('abstract' => array('App\Contracts\Repositories\RealworksRepository' => 'App\Repositories\RealworksRepository', 'App\Contracts\Repositories\PropertyRepository' => 'App\Repositories\PropertyRepository', 'App\Contracts\Repositories\SlideRepository' => 'App\Repositories\SlideRepository'))) in Container.php line 1093
at Container->getAlias(array('App\Contracts\Repositories\RealworksRepository' => 'App\Repositories\RealworksRepository', 'App\Contracts\Repositories\PropertyRepository' => 'App\Repositories\PropertyRepository', 'App\Contracts\Repositories\SlideRepository' => 'App\Repositories\SlideRepository')) in Application.php line 703
at Application->make(array('App\Contracts\Repositories\RealworksRepository' => 'App\Repositories\RealworksRepository', 'App\Contracts\Repositories\PropertyRepository' => 'App\Repositories\PropertyRepository', 'App\Contracts\Repositories\SlideRepository' => 'App\Repositories\SlideRepository'), array()) in Container.php line 231

I have verified that all namespaces in the $services array are valid and all those classes exist. What am I doing wrong?

Please sign in or create an account to participate in this conversation.