Home > Article > PHP Framework > How to open command in laravel
Laravel is a popular PHP framework. It is easy to use, highly scalable, and has high code reusability. It is loved by more and more developers. When using Laravel, we can use commands to complete some common development tasks, such as generating controllers, creating database migrations, etc. Next, this article will introduce how to use the command line of Laravel.
1. Prerequisites
Before using Laravel’s command line tools, we need to install Laravel first. For the installation method of Laravel, please refer to Laravel official documentation.
2. How to open the command line tool
In the Windows system, you can open the run window through the Win R shortcut key, enter "cmd" and press the Enter key to open the command line terminal.
In MacOS system, you can use the "Terminal" application, or you can use the Spotlight search box to enter "Terminal" to open it.
3. Use Laravel’s command line tool
php artisan
This will list all available, registered Laravel commands. In addition, you can also use the "help" command to view the help documentation for a single command, such as:
php artisan help make:controller
Generate controller:
php artisan make:controller UserController
Generate model:
php artisan make:model User
Create database migration:
php artisan make:migration create_users_table
Generate resource controller:
php artisan make: controller --resource UserController
Generate authentication controller:
php artisan make:auth
php artisan migrate
Use the following command to roll back the most recent migration operation:
php artisan migrate:rollback
php artisan db:seed
php artisan serve
By default, the server will listen on port 8000. The port number can be changed by adding the "--port" option:
php artisan serve --port=8888
php artisan cache:clear
Generate route cache:
php artisan route:cache
Clear route cache:
php artisan route :clear
Create a new event class in the specified namespace:
php artisan event:generate YourEvent
Generate task:
php artisan make:job YourJob
Push tasks to the queue:
php artisan queue:work
php artisan make:command CustomCommand
Then write the execution code in the generated command class. In order for Laravel to recognize the command, you can register the command into the console kernel.
4. Summary
Laravel’s command line tool brings a lot of convenience to our development process. Mastering the use of command line tools can greatly improve development efficiency. I hope the content introduced in this article is helpful to you.
The above is the detailed content of How to open command in laravel. For more information, please follow other related articles on the PHP Chinese website!