Before reading this article, you must have heard of the term “command line” and used it, so what is it? and what command lines are commonly used in Laravel? Let’s find out together.
The command line, also known as the command line, is an interface designed so that the user can command the computer to do just the keyboard through commands in the form of a command prompt (prompts). And of course, it exists in all popular operating systems today (Windows, Mac, Linux…). As for a programmer, a command line is an indispensable tool, it helps you save a lot of time in the working process.
Here are the command lines you will encounter most when working with Laravel:
The command to load Laravel via Composer :
composer create-project laravel/laravel example-app
Command to run the virtual server in Laravel:
php artisan serve
The command helps you to see all the routes available in laravel:
php artisan route:list
Command to create controller in Laravel :
php artisan make:controller UserController
Command to create controller with 7 CRUD functions in Laravel :
php artisan make:controller UserController --resource
The command to create Migration in Laravel:
php artisan make:migration create_users_table
Command to run Migration:
php artisan migrate
The statement returns based on the data written to the migrations table and reruns the migration:
php artisan migrate:refresh
The statement deletes all tables, doesn’t care about rollbacks, and runs the migration again:
php artisan migrate:fresh
The command to create a Seeder file in Laravel:
php artisan make:seeder UsersTableSeeder
Command to run specific Seeder file with class name in Laravel:
php artisan db:seed --class=UsersTableSeeder
The command to create Model Factory for the users table:
php artisan make:factory UserFactory
The command to delete all data tables and rerun the migration then run the DatabaseSeeder file, possibly calling multiple seeder classes:
php artisan migrate:fresh --seed
The command to create Model in Laravel :
php artisan make:model User
Combined command to create Model and Controller in Laravel:
php artisan make:model User -c
Combined command to create Model, Controller and Migration in Laravel:
php artisan make:model Category -mc
Combined statement to create Model, Controller + 7 CRUD and Migration functions in Laravel:
php artisan make:model User -mcr
Command to create a test file:
php artisan make:test UserTest
To run the test we have the following options:
<!-- wp:paragraph -->
./vendor/bin/phpunit
<!-- wp:paragraph -->
./vendor/bin/phpunit --testsuite Unit
<!-- wp:paragraph -->
./vendor/bin/phpunit tests/Unit/ExampleTest.php
<!-- wp:paragraph -->
./vendor/bin/phpunit --testdox