Get ready to welcome Laravel package auto-discovery

June 8, 2017 By - Usama Muneer
    • laravel-banner

      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.

      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.

      Comments

      comments

    blog user
    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.

    Related Posts

    Manually Installing composer is an advanced technique, however there are several reasons why a developer might prefer this reason instead of using the interactive installation routine.

    Working with Laravel is amazing it feels magical but sometimes you get stuck in those magics Laravel is doing for you behind the scene.

    You guys might have noticed this little piece of warning while running composer in your command line