When making a Laravel package, how do I register the service provider and alias of dependency packages?
laravel, package
Solution
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');
}
Problem
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 /workbench/vendor/package/src/composer.json I have: ``` "require": { "php": ">=5.3.0", "illuminate/support": "4.1.*", "edvinaskrucas/notification": "2.*" } ``` I'm then registering the service provider in my package's service provider's register method (not even sure if this is the right way to do this), and the alias using App::alias. So in /workbench/vendor/package/src/Vendor/Package/PackageServiceProvider.php I have: ``` public function register() { App::register('Krucas\Notification\NotificationServiceProvider'); App::alias('Notification','Krucas\Notification\Facades\Notification'); } ``` But I'm still getting "Class 'Notification' not found" exception when attempting to use Notification::info() in a controller or Notification::showAll() in a view. How do I properly register service providers for my package's dependencies?