Composer Autoloading is a feature in Laravel that leverages Composer's PSR-4 autoloading standard to automatically load PHP classes. It eliminates the need for manual require
or include
statements, improving code organization.
Composer, a dependency management tool for PHP, introduced autoloading standards to simplify class loading. Laravel integrates this feature by default.
composer dump-autoload
after adding new classes.To autoload a custom namespace:
composer.json
:"autoload": {
"psr-4": {
"App\\Services\\": "app/Services/"
}
}
composer dump-autoload
Now you can use the classes in the App\Services
namespace without manually requiring them.