A simple way to selectively load dev packages into Laravel

Warrick Bayman
Aug 28, 2017 · 1 min read

NOTE: 18 October 2017

So with the release of Laravel 5.5, this isn’t really needed anymore. Laravel 5.5 now has a package discovery feature so there is no need to add supported packages to your app.php config anymore. Simply install the package and you’re good to go.


Here’s a little snippit I use all the time. It allows you add packages to your Laravel installation selectively based on the environment you’re working in. There’s always those dev packages you don’t want, or shouldn’t have in production, so they get added to require-dev. Cool, but then you have non-production packages all over your app.php config file in production code. I think that’s crap.

So I wrote a super-simple Service Provider for Laravel that will let you load dev packages ONLY when working in your dev environment.

Stick it in your Providers directory, and add the following line to the $providers array in config/app.php.

App\Providers\DevelopementServiceProvider::class,

Now you can add your dev packages to the $providers member array and they’ll only get loaded when your APP_ENV is local. You can also load facades selectively by listing them in the $facades member array.

)

Warrick Bayman

Written by

Designer, developer, musician, cyclist (well... I own a bike).

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade