Open In App
Related Articles

Difference Between “php artisan dump-autoload” and “composer dump-autoload”

Like Article
Save Article
Report issue

PHP Artisan: Artisan is a command-line UI that can aid you while you build your application. PHP artisan command performs multiple tasks in less time and is more efficient. It can be used to create a model, to create a cache, to create a controller, and can also be used to create Laravel packages and add dummy data too. PHP artisan serve: This command can be used to run your application. It is used for developing and testing purposes as well.

  • By default, it takes hostname as the localhost.
php artisan serve
  • If you want to change the hostname as well as the port number, you can use the following command.
php artisan serve --port=8080

Usage of PHP artisan command: The important thing you need to know while using Laravel is, running your project through localhost is not possible, it can be run only through the php artisan serve command itself.

  • Create the model: This command will generate the model username.php into the pre-existing Models folder or if the folder does not exist it will create one. You can find the model in this location app/Models/modelname.php
php artisan make:model
  • Clear cache: When more users register for your website it might cause the authentication system to fail, the cache in the laravel can be cleared by using these commands. You can also remove all cache files and session files from storage manually as well.
    • To flush the application cache
php artisan cache:clear
  • To remove configuration cache file
php artisan config:clear
  • To clear all the compiled view files
php artisan view:clear 
  • Create Controller: The following command is used to create the controller. Generates TestController inside the Controller folder
php artisan make:controller TestController

PHP artisan dump-autoload: The php artisan dump-autoload command call the Composer with optimize flag. It will recompile loads of files creating the huge bootstrap/compiled.php PHP Composer The composer is an application-level package manager for PHP Programming language. A composer is a tool for managing the dependencies in PHP. There are several commands which you need to know before using the composer tool.

  • Composer.json: To begin using composer all you need is a composer.json file. This file includes all the dependencies of your created project and the metadata as well. composer.json 


    "files":["name1.php", "name2.php"]

  • Composer install: The composer install command can be used to add on the dependencies. This command will not update anything. You need to add it manually to the composer.json file whereas if composer.lock already exists install exactly what is specified on this file otherwise read composer.json file to make it easier.
  • Composer update: The composer update command can be used to install as well as update the dependencies. This command can be used to add or remove the dependencies but first, add manually to the composer.json file.
  • Composer remove: This command can be used to remove unused dependencies. You can uninstall such dependencies using the below command.
composer remove packageauthor/packagename
  • Composer dump-autoload: The composer dump-autoload will not download any new thing, all it does is looking for all the classes and files it needs to include again.

Difference Between “PHP artisan dump-autoload” and “PHP composer dump-autoload”: Let us now take a brief look to understand the difference between the composer dump-autoload and PHP artisan dump-autoload commands.

composer dump-autoloadphp artisan dump-autoload
It regenerates the list of all the classes that need to be included in the project (autoload_classmap.php).It will ‘recompile’ loads of files creating the huge bootstrap/compiled.php
It wont’t download any new thing to the project.It will call the composer with optimize flag.
Find all the workbench packages and composer dump-autoload them, one by one.It will use composer for some functions.
This command is supported in all Laravel versions.This command is deprecated in Laravel 5 and above versions.

Last Updated : 29 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Similar Reads