Laravel Artisan Commands Every Laravel Developer Should Know
A practical guide to essential Laravel Artisan commands that help developers manage applications, generate code, work with databases, debug issues, clear caches, and improve everyday Laravel development workflows.
Laravel Artisan Commands Every Laravel Developer Should Know
Laravel Artisan is one of the most useful tools available to Laravel developers. It provides a command-line interface for performing common development and application-management tasks.
Whether you are creating controllers, working with migrations, clearing caches, checking routes, or debugging an application, Artisan can significantly speed up your workflow.
In this guide, we will look at some of the most useful Artisan commands that Laravel developers should know.
1. Check Laravel Version
This command displays the Laravel version currently installed in your project.
It is useful when checking the framework version before installing packages, debugging compatibility issues, or working on an existing project.
2. List Available Commands
This displays the available Artisan commands in your Laravel application.
It is useful when you are unsure which command is available for a particular task.
3. Create a Controller
Laravel can automatically generate controllers using the make:controller command.
4. Create a Model
Models are used to interact with database tables through Laravel's Eloquent ORM.
You can also generate a model together with a migration:
5. Create a Migration
Migrations allow developers to define and modify database structures using PHP code.
After creating a migration:
6. Check Migration Status
This command shows which migrations have already been executed and which migrations are still pending.
It is particularly useful when troubleshooting database-related issues.
7. Roll Back Migrations
This rolls back the latest migration batch.
It can be useful during development when you need to undo a recent database change.
8. Clear Laravel Caches
This is one of the most useful commands when troubleshooting Laravel applications.
It clears Laravel's cached configuration, routes, views, events, and other optimized files.
9. Check Application Routes
This displays the routes registered in the application.
It is extremely useful when debugging routing problems and checking middleware, HTTP methods, controllers, and route names.
10. Create a Form Request
Form Requests allow validation and authorization logic to be separated from controllers.
This helps keep controllers cleaner and easier to maintain.
11. Create an API Resource
Laravel API Resources allow developers to control how model data is transformed before being returned from an API.
They are particularly useful when building REST APIs.
12. Use Laravel Tinker
Tinker provides an interactive shell for working with Laravel applications.
It can be used to query models, test relationships, and experiment with application logic without creating temporary routes or controllers.
13. Create a Seeder
Seeders are used to populate the database with initial or test data.
You can execute seeders with:
You can also migrate and seed together:
14. Create Middleware
Middleware can inspect and filter HTTP requests before they reach the application's controller.
They are commonly used for authentication, authorization, role checking, and request filtering.
15. Work With Queues
Laravel queues allow time-consuming tasks to be processed in the background.
They are useful for tasks such as sending emails, processing files, generating reports, and other operations that should not block a web request.
16. Check Scheduled Tasks
This command helps inspect scheduled tasks configured in a Laravel application.
Scheduled tasks are useful for recurring jobs such as reports, cleanup operations, notifications, and automated maintenance.
17. Clear Configuration Cache
This command clears the cached configuration.
It can be useful when configuration or environment changes are not being reflected as expected.
Conclusion
Laravel Artisan provides a powerful collection of commands that can make everyday development significantly easier.
Instead of manually creating files, modifying database structures, checking routes, or troubleshooting cached resources, developers can use Artisan to perform many of these tasks quickly and consistently.
The best way to become comfortable with Artisan is to use these commands regularly while building real Laravel applications.Laravel Artisan Commands Every Laravel Developer Should Know
Laravel Artisan is one of the most useful tools available to Laravel developers. It provides a command-line interface for performing common development and application-management tasks.
Whether you are creating controllers, working with migrations, clearing caches, checking routes, or debugging an application, Artisan can significantly speed up your workflow.
In this guide, we will look at some of the most useful Artisan commands that Laravel developers should know.
1. Check Laravel Version
This command displays the Laravel version currently installed in your project.
It is useful when checking the framework version before installing packages, debugging compatibility issues, or working on an existing project.
2. List Available Commands
This displays the available Artisan commands in your Laravel application.
It is useful when you are unsure which command is available for a particular task.
3. Create a Controller
Laravel can automatically generate controllers using the make:controller command.
4. Create a Model
Models are used to interact with database tables through Laravel's Eloquent ORM.
You can also generate a model together with a migration:
5. Create a Migration
Migrations allow developers to define and modify database structures using PHP code.
After creating a migration:
6. Check Migration Status
This command shows which migrations have already been executed and which migrations are still pending.
It is particularly useful when troubleshooting database-related issues.
7. Roll Back Migrations
This rolls back the latest migration batch.
It can be useful during development when you need to undo a recent database change.
8. Clear Laravel Caches
This is one of the most useful commands when troubleshooting Laravel applications.
It clears Laravel's cached configuration, routes, views, events, and other optimized files.
9. Check Application Routes
This displays the routes registered in the application.
It is extremely useful when debugging routing problems and checking middleware, HTTP methods, controllers, and route names.
10. Create a Form Request
Form Requests allow validation and authorization logic to be separated from controllers.
This helps keep controllers cleaner and easier to maintain.
11. Create an API Resource
Laravel API Resources allow developers to control how model data is transformed before being returned from an API.
They are particularly useful when building REST APIs.
12. Use Laravel Tinker
Tinker provides an interactive shell for working with Laravel applications.
It can be used to query models, test relationships, and experiment with application logic without creating temporary routes or controllers.
13. Create a Seeder
Seeders are used to populate the database with initial or test data.
You can execute seeders with:
You can also migrate and seed together:
14. Create Middleware
Middleware can inspect and filter HTTP requests before they reach the application's controller.
They are commonly used for authentication, authorization, role checking, and request filtering.
15. Work With Queues
Laravel queues allow time-consuming tasks to be processed in the background.
They are useful for tasks such as sending emails, processing files, generating reports, and other operations that should not block a web request.
16. Check Scheduled Tasks
This command helps inspect scheduled tasks configured in a Laravel application.
Scheduled tasks are useful for recurring jobs such as reports, cleanup operations, notifications, and automated maintenance.
17. Clear Configuration Cache
This command clears the cached configuration.
It can be useful when configuration or environment changes are not being reflected as expected.
Conclusion
Laravel Artisan provides a powerful collection of commands that can make everyday development significantly easier.
Instead of manually creating files, modifying database structures, checking routes, or troubleshooting cached resources, developers can use Artisan to perform many of these tasks quickly and consistently.
The best way to become comfortable with Artisan is to use these commands regularly while building real Laravel applications.