Package Auto-Discovery In Laravel 5.5

Taylor Otwell
Jun 1, 2017 · 2 min read

For Laravel 5.5, which is due for release near the end of July or beginning of August, long time community member Dries Vints and I teamed up to make it much easier to install and enable packages.

Package developers will now be able to add a new section to their composer.json files that inform the framework of any service providers or facade aliases that should be registered. In fact, I have already submitted a pull request to add this configuration to the popular “Laravel Debugbar” package by Barry vd. Heuvel.

Now, on a fresh copy of Laravel 5.5, I can simply require the package:

composer require barryvdh/laravel-debugbar:dev-master

And the package’s service provider will automatically be registered and enabled:

Image for post
Image for post

This eliminates much of the headache around installing and consuming packages. For example, if an auto-discovery enabled Composer package is installed in the require-dev portion of your composer.json file, its service provider will only be registered when your “dev” dependencies are installed. This is fantastic for packages like Laravel Dusk that should only be available in a “dev” environment. No more conditional service provider registration cluttering up your AppServiceProvider.

Of course, we can easily remove installed packages and their discovered providers and aliases will be removed as well:

composer remove barryvdh/laravel-debugbar

It is also easy to disable auto-discovery for one or more packages by listing them in a dont-discover portion of your application’s composer.json file:

Image for post
Image for post

This addition to Laravel 5.5 makes it a cinch to start using all kinds of community developed packages. I can’t wait for you to try it.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store