Laravel’s command-line tool, Artisan, is one of its most powerful features. Artisan helps streamline repetitive tasks, scaffold code, and manage the application efficiently, all without leaving your terminal. Whether you’re a beginner or a seasoned Laravel developer, these 10 Artisan commands will save you time and make your development workflow smoother.
1. PHP Artisan List
This command displays all the available artisan commands at the moment. You can use this command to your benefit easily.
php artisan list
2. PHP Artisan Help <command>
What it does is provide details and usage options for specific commands, which is very useful if you are a beginner in Laravel. It also might help professionals at some point.
php artisan help make:model
In the place of “model,” you can write down any command name that you want to know the details.
3. PHP Artisan Make:model
What it does is create models for Laravel, allowing you to use those models to suit your needs as needed. You can also add -m to also create a migration, -c for a controller, and -f for a factory in one go.
php artisan make:model Product -mc
In place of Product you can add your model name.
4. PHP Artisan Migrate
What it does is, it migrates all the database tables to the database at once. Which can make your life a lot easier.
php artisan migrate
Bonus:
Rollback last migration:
php artisan migrate:rollbackReset all:
php artisan migrate:resetFresh start:
php artisan migrate:fresh
5. PHP Artisan Make:controller
What it does is it creates a controller which can help you control the specific part or function in your program, which makes things easier, for example HomeController controls all the program regarding the home page. You can add –resource to generate RESTful methods automatically.
php artisan make:controller PostController –resource
6. PHP Artisan Route:list
What it does is it lists all registered routes in your application. And it can be very useful for debugging, checking middlewares, or just reviewing your route structure. Tip: Add –compact or –columns=method,uri,name to filter the output, and it might be helpful to you in various ways.
php artisan route:list
7. php artisan tinker
What it does is open a REPL (Read–Eval–Print Loop) to interact with your Laravel app from the terminal. This makes a developer’s life a lot easier and is also helpful while developing complicated applications. Also, this is great for testing database queries, creating records, or experimenting with Eloquent.
php artisan tinker
Example: User::factory()->count(5)->create();
8. php artisan config:cache
What it does is it caches your config file for a faster experience. You have to run this command after changing your config file to make sure the changes are applied properly.
php artisan config:cache
Bonus Tip: Use php artisan config:clear if you need to clear the cached config files.
9. php artisan make:migration
What it does is it creates new migration files, and migrations help you version-control your database schema.
php artisan make:migration create_orders_table
Add –table=orders to modify a table or –create=orders to create a new one.
10. php artisan serve
What this command does is simple, but the most important one. It runs your application on a local server, and you can use the application in your web browser for testing and so on , which helps the developer in various ways.
php artisan serve
In conclusion
In this article we talked about the 10 most usefull artisan commands that can help you make your life alot more easier if you are a begginer in laravel and even if you are pro it is must to help you in many ways so make sure to visit us for more of these on coding.
Thanks for Visiting Code Issue Hub.