PHPackages                             sebastiaanluca/laravel-conditional-providers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sebastiaanluca/laravel-conditional-providers

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

sebastiaanluca/laravel-conditional-providers
============================================

Load Laravel service providers based on the current environment.

5.0.0(6y ago)2633.7k5MITPHPPHP ^7.3

Since Jan 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/sebastiaanluca/laravel-conditional-providers)[ Packagist](https://packagist.org/packages/sebastiaanluca/laravel-conditional-providers)[ Docs](https://github.com/sebastiaanluca/laravel-conditional-providers)[ RSS](/packages/sebastiaanluca-laravel-conditional-providers/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (10)Used By (0)

Laravel Conditional Providers
=============================

[](#laravel-conditional-providers)

[![Latest stable release](https://camo.githubusercontent.com/923505f8737cf0700cc52a293588c9b566e9148cc3bb4ab70ba09d5be6fe31e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365626173746961616e6c7563612f6c61726176656c2d636f6e646974696f6e616c2d70726f7669646572732e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/sebastiaanluca/laravel-conditional-providers)[![Software license](https://camo.githubusercontent.com/08662bb339bee903c7279b82f3217310d3f196fdfa63b019d294ae85e1a5d7d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d696e666f726d6174696f6e616c2e737667)](LICENSE.md)[![Build status](https://camo.githubusercontent.com/66d1ba9d404d59e7cd15f0df574668d11394f59132afc530835bb08186cc4713/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7365626173746961616e6c7563612f6c61726176656c2d636f6e646974696f6e616c2d70726f7669646572732f6d61737465722e737667)](https://travis-ci.org/sebastiaanluca/laravel-conditional-providers)[![Total downloads](https://camo.githubusercontent.com/58f78a99f260c202d34ed793981359d8f0b1f5afecfc0850cb59d491b0e61496/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365626173746961616e6c7563612f6c61726176656c2d636f6e646974696f6e616c2d70726f7669646572732e7376673f636f6c6f723d627269676874677265656e)](https://packagist.org/packages/sebastiaanluca/laravel-conditional-providers)[![Total stars](https://camo.githubusercontent.com/da8d7b5188c2e50b84d7625751fcb8a9ca50d5db16a657653c09ef29e4de3870/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7365626173746961616e6c7563612f6c61726176656c2d636f6e646974696f6e616c2d70726f7669646572732e7376673f636f6c6f723d627269676874677265656e)](https://github.com/sebastiaanluca/laravel-conditional-providers)

[![Read my blog](https://camo.githubusercontent.com/0760b582e22202bd412feb64f5f87b6459f64a0b8ea5fdd24cbadf87df736177/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b2d626c6f672d6c69676874677265792e737667)](https://blog.sebastiaanluca.com)[![View my other packages and projects](https://camo.githubusercontent.com/5ce3a83ee0ec2b4ae47a99f67347c1d8e78582757eca80fe31c98e5bd0e2185a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b2d6f746865725f7061636b616765732d6c69676874677265792e737667)](https://packagist.org/packages/sebastiaanluca)[![Follow @sebastiaanluca on Twitter](https://camo.githubusercontent.com/bde346ed8efc8b2458386b36256c64e3fe010276f449b80fe4f663c4c8bbd83e/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f7365626173746961616e6c7563612e7376673f7374796c653d736f6369616c)](https://twitter.com/sebastiaanluca)[![Share this package on Twitter](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Check%20out%20this%20extensive%20set%20of%20generic%20PHP%20helper%20functions%20and%20classes!%20Via%20@sebastiaanluca%20https://github.com/sebastiaanluca/laravel-conditional-providers)

**Load Laravel service providers and facades based on the current environment.**

Specify the service providers and facades to load per environment directly in your configuration file. No more need to add lengthy blocks of conditionals to your `AppServiceProvider`, do it all in the app configuration file like you would with any service provider and facade!

Inspired by [Matt Staufer](https://mattstauffer.co/blog/conditionally-loading-service-providers-in-laravel-5), [Sven Luijten](https://github.com/svenluijten/env-providers), and others.

Table of contents
-----------------

[](#table-of-contents)

- [What does it solve?](#what-does-it-solve)
- [Requirements](#requirements)
- [How to install](#how-to-install)
- [How to use](#how-to-use)
    - [Conditional providers](#conditional-providers)
    - [Conditional aliases](#conditional-aliases)
- [License](#license)
- [Change log](#change-log)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [About](#about)

What does it solve?
-------------------

[](#what-does-it-solve)

Say you're using a package like [barryvdh/laravel-ide-helper](https://github.com/barryvdh/laravel-ide-helper) in your project. If you've followed its installation instructions and require it only in development environments (like you should), you'd do the following:

```
composer require barryvdh/laravel-ide-helper --dev
```

And then add the service provider to your app's config providers array:

```
'providers' => [

    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

]
```

Now when you run `composer install --no-dev` in your production environment to install all but development packages, this will throw an exception. Laravel will try to load the registered service provider class which it can't find, because the package is not installed.

```
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found

```

Of course you can —per the instructions— conditionally load the provider manually in the register method of the `app/Providers/AppServiceProvider.php` file:

```
public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
    }
}
```

But you'd have to do this for each development package and each environment you don't want it loaded in, which is hardly maintainable and pollutes your application-specific code.

Enter Laravel conditional providers [to easily do all of this](#how-to-use) in your main application config file!

Requirements
------------

[](#requirements)

- PHP 7.3 or higher
- Laravel 6.0 or higher

How to install
--------------

[](#how-to-install)

```
composer require sebastiaanluca/laravel-conditional-providers
```

How to use
----------

[](#how-to-use)

### Conditional providers

[](#conditional-providers)

Disable auto-discovery of the package's service provider by adding it to your composer.json's relevant section:

```
"extra": {
    "laravel": {
        "dont-discover": [
            "barryvdh/laravel-debugbar"
        ]
    }
},
```

Once you're set up, simply **add a providers array per environment** to your `config/app.php` file:

```
'providers' => [

    // Contains your global providers which will load in any environment

],

'local_providers' => [

    // Contains your 'local' environment providers

    // Mostly used to load debug helpers, optimization tools, et cetera

    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
    Barryvdh\Debugbar\ServiceProvider::class,

],

'production_providers' => [

    // Contains your 'production' environment providers

    // Great for when you only want to get analytics or
    // bug reports in production and disable the provider
    // entirely when developing.

],
```

Each providers key is **optional** and can be empty —so you could just use the `local_providers` array or none at all.

The example above will do the following in a `local` environment:

- Load every provider from `providers`
- Load every provider from `local_providers`
- Ignore everything in `production_providers`

All done! Now your app service provider is clean and you get a better view on what's loaded and when, with the added benefit of enabling or disabling packages based on environment.

### Conditional aliases

[](#conditional-aliases)

In addition to conditionally loading providers, this workflow is also available for aliases/facades. **Add a facades/aliases array per environment** to your `config/app.php` file like so:

```
'aliases' => [

    // Contains your global aliases which will load in any environment

],

'local_aliases' => [

    // Contains your 'local' environment aliases/facades

    'Debugbar' => Barryvdh\Debugbar\Facade::class,

],

'production_aliases' => [

    // Contains your 'production' environment aliases/facades

],
```

That's it! This will load the `Debugbar` facade only in the local environment.

License
-------

[](#license)

This package operates under the MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer install
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastiaan Luca](https://github.com/sebastiaanluca)
- [All Contributors](../../contributors)

About
-----

[](#about)

My name is Sebastiaan and I'm a freelance Laravel developer specializing in building custom Laravel applications. Check out my [portfolio](https://www.sebastiaanluca.com) for more information, [my blog](https://blog.sebastiaanluca.com) for the latest tips and tricks, and my other [packages](https://packagist.org/packages/sebastiaanluca) to kick-start your next project.

Have a project that could use some guidance? Send me an e-mail at !

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~169 days

Recently: every ~149 days

Total

8

Last Release

2260d ago

Major Versions

0.1.0 → 1.0.02017-07-13

1.1.0 → 2.0.02018-09-04

2.0.0 → 3.0.02019-03-01

3.0.1 → 4.0.02019-08-11

4.0.0 → 5.0.02020-04-24

PHP version history (4 changes)0.1.0PHP ^7.0

1.0.0PHP ^7

2.0.0PHP ^7.2

5.0.0PHP ^7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/711940?v=4)[Sebastiaan Luca](/maintainers/sebastiaanluca)[@sebastiaanluca](https://github.com/sebastiaanluca)

---

Top Contributors

[![sebastiaanluca](https://avatars.githubusercontent.com/u/711940?v=4)](https://github.com/sebastiaanluca "sebastiaanluca (84 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (1 commits)")

---

Tags

configurationdebugenvironmentlaravelpackagephpproductionprovidersservicelaravelenvironmentservice providerconditional

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sebastiaanluca-laravel-conditional-providers/health.svg)

```
[![Health](https://phpackages.com/badges/sebastiaanluca-laravel-conditional-providers/health.svg)](https://phpackages.com/packages/sebastiaanluca-laravel-conditional-providers)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8015.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k30](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
