Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Providers Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation:

    composer require juy/providers:1.*
    

    Add Juy\Providers\ServiceProvider::class to config/app.php under the providers array.

  2. 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.

  3. 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.


Implementation Patterns

Core Workflow

  1. 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.

  2. 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.

  3. Environment-Specific Providers: Use Laravel’s config caching + environment variables to toggle providers:

    'providers' => [
        env('ENABLE_DEBUG_TOOLBAR') ? 'barryvdh/laravel-debugbar' : [],
    ],
    
  4. Integration with Package Development: For reusable packages, publish a providers.php config file to let users extend their setup without modifying app.php.

Best Practices

  • Order Matters: List providers in dependency order (e.g., database before auth).
  • Leverage Autoloading: Prefer FQCNs (Fully Qualified Class Names) for local providers to avoid manual classmap updates.
  • Testing: Mock config/providers.php in tests to isolate provider behavior:
    $this->app->instance('config', [
        'providers' => ['MockProvider'],
    ]);
    

Gotchas and Tips

Pitfalls

  1. Config Caching: After modifying providers.php, clear the config cache:

    php artisan config:clear
    

    Forgetting this may leave old providers/aliases active.

  2. 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,
    ],
    
  3. 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.

  4. 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();
        });
    }
    

Debugging Tips

  • Verify Loading: Check if providers are registered by inspecting the container:
    $this->app->has('provider-class-name'); // Returns bool
    
  • Logs: Enable Laravel’s debug mode (APP_DEBUG=true) to catch booting errors.
  • Config Overrides: Use config(['providers.providers' => []]) to temporarily disable providers during debugging.

Extension Points

  1. 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');
        }
    }
    
  2. 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.

  3. 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',
    ],
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver