Updated April 11, 2023
Laravel Commands
Laravel command is the most popular and widely used PHP framework, which is based on MVC (Model View Controller) Architecture. It is an open-source web application development framework and was created by Taylor Otwell. As of now, the most recent release of the laravel framework is Laravel 5.7, which was released in September 2018.
Prerequisites for starting with laravel
You should know basic/intermediate of:
- PHP
- HTML / CSS
- Working of MVC Model
- DB knowledge
Composer and Artisan
A composer is a tool which allows the user to create any project with respect to a given framework. It consists of all the dependencies and libraries.
Artisan is the command-line interface of Laravel. It has a set of commands which will be discussing now in details which helps in building a web application.
Artisan command syntax:
php artisan [ options] [ arguments]
Basic Laravel Commands
Some of the basic laravel commands are mentioned below:
1. To list out all the Artisan commands
php artisan list: This command will list all the available commands that are a part of laravel – artisan console.
It starts with giving the syntax of executing the command i.e.
php artisan [command] [options] [arguments]
where,
- options: It can be used like –h (for help), -q (for quiet), -v (for version) etc.
- commands: It can be used as per command name followed by options and arguments. Few of the commands are migrate, serve, make, help, etc.
2. php artisan help <command-name>
This command is used to get help on a particular command name. Let’s say if you would like to know more about the usage and meaning of the command, you can get it by making use of the help utility provided by Artisan.
php artisan help makes:auth
where
- make: auth: It is the command name for which we would like to know more.
php artisan –version
This command will list out the version of the Laravel framework which you are using.
php artisan down
This command is used to put the laravel application under maintenance mode.
php artisan up
This command is used to bring back the laravel application up and running.
php artisan env
This command will tell you the environment in which the laravel application is running.
php artisan view: clear
This laravel command will clear all the compiled view files.
php artisan route: list
This command will list all the registered routes.
php artisan route: clear
This command will clear all the route cache file.
php artisan route: cache
This command creates a route cache file for faster route registration
Intermediate Laravel Commands
Some of those kinds of requiring intermediate laravel commands are mentioned below:
php artisan serve
This command is used to start a laravel project, and by default, the application will be hosted at localhost with port number 8000
php artisan make: model EduCBA
This command is used to create a new model class.
If we execute the command, php artisan list, we will find a couple of makes commands. In order to see the list of make commands, please press the shift + pg down key on your keyboard to navigate through all the pages.
php artisan make: controller UserController
This command will create a new controller file in the below folder:
App/Http/Controllers
php artisan make- request EduCBA_BlogPost
This command is used to create a new form request class in the below folder:
app/Http/Requests
php artisan make seeder EduCBASeeder
This command is used to create a new database seeder class.
php artisan make middleware Middleware_Name
This command is used to create a new middleware class.
php artisan make: policy OurPolicy
This command is used to create a new policy class.
php artisan make: mail Course_Enrolled@EduCBA
This command is used to create a new email class.
php artisan make: event EduCBA_Analytics_Enrolled
This command is used to create a new even class.
php artisan make: command compose_email
This command is used to create a new artisan Laravel command
Advance Laravel Commands
Below are Some of the advanced laravel commands, which are as follows:
php artisan make: model Project --migration --controller --resource
This command is used to create a new migration file for the model(migration), create a new controller for the model(controller) and to have a resource controller for the generated controller.
php artisan make:listener SendEnrollement_Notification
This command is used to create a new event listener class.
php artisan migrate [--bench="vendor/package"] [--database[="..."]] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]
This command is used to do Database migration.
php artisan vendor: publish
This command is used to publish any publishable assets from vendor packages.
php artisan make provider OurServiceProvider
This command is used to create a new service provider class.
php artisan migrate:make name [--bench="vendor/package"] [--create] [--package[="..."]] [--path[="..."]] [--table[="..."]]
This command is used to create a new migration file
php artisan make job SendReminderEmail_for_ANalytocs@EduCBA
This command is used to create a new job class.
Recommended Articles
We hope that this EDUCBA information on “laravel commands” was beneficial to you. You can view EDUCBA’s recommended articles for more information.