Introduction
Artisan is the command-line interface included with Laravel, providing numerous commands to assist in building applications. This cheatsheet covers essential commands for various tasks such as creating models, migrations, controllers, and more.
General Commands
php artisan list
- Display Help for a Command
php artisan help [command]
- Display the Current Laravel Version
php artisan --version
Environment
php artisan config:cache
- Clear Configuration Cache
php artisan config:clear
php artisan route:cache
php artisan route:clear
php artisan view:cache
php artisan view:clear
php artisan cache:clear
Database
php artisan migrate
- Rollback the Last Migration Operation
php artisan migrate:rollback
php artisan migrate:reset
php artisan migrate:refresh
- Fresh Migration (Rollback and Run All)
php artisan migrate:fresh
php artisan db:seed --class=SeederClassName
php artisan make:migration create_table_name
php artisan make:seeder SeederName
php artisan make:factory FactoryName
Models, Controllers, and More
php artisan make:model ModelName
- Create a Model with Migration
php artisan make:model ModelName -m
php artisan make:controller ControllerName
- Create a Resource Controller
php artisan make:controller ControllerName --resource
php artisan make:middleware MiddlewareName
php artisan make:event EventName
php artisan make:listener ListenerName
php artisan make:job JobName
php artisan make:command CommandName
Development
- Serve the Application Locally
php artisan serve
php artisan key:generate
php artisan test
- Optimize the Framework for Better Performance
php artisan optimize
- Clear Compiled Classes and Services
php artisan clear-compiled
Queue and Jobs
- Start Processing Jobs on the Queue
php artisan queue:work
- Restart Queue Worker Daemon
php artisan queue:restart
php artisan queue:flush
Miscellaneous
- Create a New Notification
php artisan make:notification NotificationName
php artisan make:mail MailClassName
php artisan make:policy PolicyName
php artisan make:rule RuleName
Conclusion
This cheatsheet provides a quick reference to the essential Laravel Artisan commands needed for day-to-day development tasks. For more detailed usage, refer to the Laravel documentation.