juy/providers
Loads Laravel service providers and aliases from a dedicated config/providers.php file to keep config/app.php clean. Group providers by app, package, local (dev), and production environments, and auto-register them via a single service provider.
Installation:
composer require juy/providers:1.*
Add Juy\Providers\ServiceProvider::class to config/app.php under the providers array.
Publish Config:
php artisan vendor:publish --provider="Juy\Providers\ServiceProvider" --tag="config"
This generates config/providers.php—the central file for managing providers and aliases.
First Use Case:
Add a local service provider or alias to config/providers.php:
return [
'providers' => [
App\Providers\LocalServiceProvider::class,
],
'aliases' => [
'LocalAlias' => App\Services\LocalService::class,
],
];
Laravel will now autoload these alongside config/app.php.
Centralized Provider Management:
Use config/providers.php to declare all non-core providers (e.g., third-party packages, local modules). Example:
'providers' => [
'package-name/package-provider', // Composer autoloaded
App\Providers\Auth\CustomAuthProvider::class,
],
Avoid cluttering config/app.php with every dependency.
Dynamic Aliases: Define aliases in the same config file to simplify facade usage:
'aliases' => [
'CustomLog' => App\Facades\CustomLogger::class,
],
Access via CustomLog::info() without manual binding.
Environment-Specific Providers: Use Laravel’s config caching + environment variables to toggle providers:
'providers' => [
env('ENABLE_DEBUG_TOOLBAR') ? 'barryvdh/laravel-debugbar' : [],
],
Integration with Package Development:
For reusable packages, publish a providers.php config file to let users extend their setup without modifying app.php.
config/providers.php in tests to isolate provider behavior:
$this->app->instance('config', [
'providers' => ['MockProvider'],
]);
Config Caching:
After modifying providers.php, clear the config cache:
php artisan config:clear
Forgetting this may leave old providers/aliases active.
Namespace Collisions:
If a provider/alias conflicts with Laravel core (e.g., Cache), prefix it in config/providers.php:
'aliases' => [
'AppCache' => Illuminate\Support\Facades\Cache::class,
],
Laravel 5.5+ Compatibility:
The package targets Laravel 5.1–5.3. For newer versions, manually merge providers.php into app.php or use a modern alternative like spatie/laravel-package-tools.
Service Provider Booting:
Providers in config/providers.php do not automatically bind to the container. Use the register() method to manually bind services:
public function register()
{
$this->app->bind('custom.service', function () {
return new CustomService();
});
}
$this->app->has('provider-class-name'); // Returns bool
APP_DEBUG=true) to catch booting errors.config(['providers.providers' => []]) to temporarily disable providers during debugging.Dynamic Provider Loading:
Extend the package by adding a boot() method to Juy\Providers\ServiceProvider to conditionally load providers:
public function boot()
{
if (app()->environment('local')) {
$this->mergeConfigFrom(__DIR__.'/config/providers.local.php', 'providers');
}
}
Custom Config Paths:
Override the default config/providers.php path by publishing a modified config file or using environment variables to specify a custom path.
Package Integration:
For packages, include a config/providers.php template in your assets and document how users should extend it. Example:
// Package config/providers.php
'providers' => [
'your-package/providers/YourPackageServiceProvider',
],
How can I help you explore Laravel packages today?