BlogLaravel Rebuild Class Autoload

22nd September 2014

When you create a Laravel package you must declare the locations of your classes in the autoload section of your composer.json. For example...

 "autoload": {
        "psr-4": {
            "Company\\Package\\": "src/"

You can also use PSR-0 (which has some backwards compatibility for use with old PEAR projects) but it's not recommended is has been superseeded by PSR-4.

You then need to run the following command to ensure that this is registered properly with Laravel...

Laravel 4

$ php artisan dump-autoload

Laravel 5

$ composer dump-autoload

If you ever decide to change the location of any of your classes then you need to make sure you run this dump-autoload command again otherwise your classes wont be found.

Let's Talk