So I am relatively new to Laravel so i'm trying to seek some advice. I've read the documentation on packages provided by laravel. Now i understand you need a service provider to connect your package to laravel like so: Blog\BlogServiceProvider::class. Now what i am trying to do is have a control panel that installs packages straight off of packagist. Now i can manipulate the composer.json file quite easily in code. However, what i am trying to work around is declaring the service provider. I think it would be inconvenient if i have a dynamic installation but you have to declare the service provider yourself. Is there a way i can dynamically register the service provider in Laravel 5?
You can dynamically add service providers through the App facade:
App::register('App\Providers\SomeServiceProvider');
Related
I am developing a Laravel Package which installs a list of dependencies.
The dependencies have their own configuration files to be published after installation.
What we need is to auto (to avoid doing it manually) modify the config files of these dependencies by our package before/after publishing them and placing them in app/config.
I found some solutions like using mergeConfigFrom() in register method of Package's service provider. But it doesn't modify file content itself, just loads the merged config.
We need to modify config file's content by the package that we developing so that we don't need to change config file manually after package installation.
For example, we install Laravel Horizon as a dependency the our package. Horizon publishes a config file called horizon.php in app/config. We need to auto modify some values for app/config/horizon.php before or after publishing that config file.
Any help will be much appreciated.
Thanks :)
This is currently not possible. Look at Illuminate\Foundation\Console\VendorPublishCommand in the laravel framework source code.
Best way to go is to completely replace horizon.php config in your package by publishing it on the same file.
Alternativly you can write a custom command to inject this data in the horizon.php
You could make a PR in laravel framework for you to allow this. and hope for the best they accept your PR.
I'm currently developing a set of packages/service providers to use as a sort of boilerplate for new web applications. I started developing some time ago and I never ran the packages through composer.
After I made a repository and added the package to a new Laravel application, it installed just fine, until it ran php artisan package:discover. The error was:
In breadcrumbs.php line 5:
Class 'Athena' not found
and it refers to this line:
Breadcrumbs::register( \Athena::getFacadeRoot()->route_name_prefix . '.dashboard.show', function ( $breadcrumbs ) {
in which \Athena:: is a facade within the package. I fixed the issue by adding the facade to the app.php file. The idea was to bootstrap applications easily, so my question is:
Can I use a facade within a package and still use the Laravel package discovery, without having to edit files when I create a new project?
I have tried to develop a custom package but ended with errors
I have a package structure in my below as given below:
can any body tell me why the package route is not working or i have done some errors?If you can provide me the links for the development of the package in laravel 5.2 then i will be very appreciated.
Please i need help.
composer
service provider
Same issue on Laravel 5.3 custom package routes will not be working.
First make sure you have registered your service provider in "config/app.php" section "providers".
And second it MUST BE after the Laravel service providers, but before the App service providers.
For me on Laravel 5.3, it worked after I put it last in the 'providers' array of config/app.php
I've built a composer package for Laravel and it uses a Service Provider. I currently load it in the "providers" array in app.php after installing it to get it to work, but it seems like there should be a way to tell Composer to do that automatically to make set up easier for developers. Is that possible, or does it have to be done manually by the developer when they make a new package?
Yes, it's required that you register the Service Provider in the app config. Even if you find a way to autoload your Service Provider with Composer, it doesn't know what a Service Provider is. You need to register it within the framework, because Laravel will handle calling your boot() and register() methods in the right order at the right time.
I'm trying to develop a custom package using "workbench". It's a simple package that will create a repository to consume a different API we have. I plan on injecting this repository into my controllers of my application. Anyway, I created the package using "workbench". This creates the service provider. The Laravel docs say to add the service provider to my "providers" array in app.config. I've done this, but when I run composer update, I get an error saying that the class is not found, specifically: PHP Fatal error: Class 'MyVendor\MyPackage\ServiceProvider not found in /.. .. .. ../laravel/vendor/framework/src/Illuminate/Foundation/ProviderRepository.php. I thought I followed the docs correctly, what am I missing?
Simply running composer install inside the workbench directory resolves this issue.