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?
Registering ProvidersAll service providers are registered in the config/app. php configuration file. This file contains a providers array where you can list the class names of your service providers. By default, a set of Laravel core service providers are listed in this array.
In JavaScript we use NPM, i.e. the Node Package Manager. For backend, Composer is a very popular dependency manager.
To initialize a new Laravel custom package development, cd into the packages/fhsinchy/inspire directory and execute the composer init command. This will start the package initialization process. Make sure to write the package name, description, and author information properly.
Service providers in laravel application is the central place where application is bootstrapped. That is, laravel's core services and our application's services, classes and their dependencies are injected in service container through providers.
During package development you should add your package service provider in composer.json file as in the code below. For additional information please consult at Laravel's Package Discovery.
"extra": {
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facade"
}
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With