Language:

Search

Get ready to welcome Laravel package auto-discovery

  • Share this:
Get ready to welcome Laravel package auto-discovery

Introduction

Over the years, Laravel has brought so much excitement in developing applications with its out of the box code-base and practices. If you’re somewhat familiar with Laravel, it utilizes Composer for dependency management.

One thing that always got me is after requiring any Laravel package, we were forced to register that corresponding package in our Facades & Service providers. Which, sometimes becomes frustrating.

Bringing in the Package Auto-Discovery

With the release of Laravel 5.5 is just round the corner, auto-discovery package comes to rescue all of the Laravel lovers.

We can’t thank Laravel enough for bringing in this great feature. We’ll never have to add those Facades & Service providers manually. Laravel will do that for us. What a good news that is?

Taylor Otwell published about this super useful package on his medium blog. Which clearly explains how this packages actually works.

If you need to install any new package,

Previously

Composer require my/package

In your app.php

My\Package\ServiceProvider::class,

Register Facades

'package' => My\Package\Facade::class,

With Package Auto-discovery

Composer require my/package

It will auto populates the Service providers and Facades for us with composer in the front seat.

"extra": {    
"laravel": {        
"providers": [            
"My\\Package\\ServiceProvider" 
       ],        
"aliases": {            
"Package": "My\\Package\\Facade"        
}    }}

Development Only?

Well, if you’re planning to use some package for dev-only, it's service providers will only be registered when your ‘dev’ dependencies are installed.

Also Read: Top 10 reasons to choose Laravel

Conclusion

Package auto-discovery is yet another useful change in the Laravel code-base, which will definitely eliminates much of a headache around installing and consuming packages.

Usama Muneer

Usama Muneer

A web enthusiastic, self-motivated & detail-oriented professional Full-Stack Web Developer from Karachi, Pakistan with experience in developing applications using JavaScript, WordPress & Laravel specifically. Loves to write on different web technologies with an equally useful skill to make some sense out of it.