When making a Laravel package, how do I register the service provider and alias of dependency packages?

前端 未结 3 1961
死守一世寂寞
死守一世寂寞 2021-01-31 12:26

I\'m creating a package for Laravel and I\'ve defined the Notification package (https://github.com/edvinaskrucas/notification) as a dependency for my package.

In /workbe

3条回答
  •  灰色年华
    2021-01-31 12:42

    I had the same problem. I had a dependency in a package and didn't want to bother the user with these dependencies, for it was a dependency in a dependency. So this is the solution. Hope it will help you!

    public function register()
    {
        /*
         * Register the service provider for the dependency.
         */
        $this->app->register('LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider');
        /*
         * Create aliases for the dependency.
         */
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('AuthorizationServer', 'LucaDegasperi\OAuth2Server\Facades\AuthorizationServerFacade');
        $loader->alias('ResourceServer', 'LucaDegasperi\OAuth2Server\Facades\ResourceServerFacade');
    }
    

提交回复
热议问题