PHP Artisan CLI Command for Laravel

Here are the commonly used php artisan CLI commands for Laravel 11:


🔹 General Commands

php artisan list                 # Show all available commands
php artisan help migrate         # Get help for a specific command
php artisan --version            # Show Laravel version

🔹 Serve Laravel Application

php artisan serve                # Run Laravel development server (default: http://127.0.0.1:8000)
php artisan serve --host=0.0.0.0 --port=8080  # Run on a public IP and custom port

🔹 Clear Cache & Config

php artisan cache:clear           # Clear application cache
php artisan config:clear          # Clear config cache
php artisan route:clear           # Clear route cache
php artisan view:clear            # Clear compiled view files
php artisan optimize:clear        # Clear all caches

🔹 Database Migrations & Seeders

php artisan migrate               # Run all migrations
php artisan migrate:rollback      # Rollback the last migration
php artisan migrate:reset         # Rollback all migrations
php artisan migrate:fresh         # Drop all tables and re-run migrations
php artisan db:seed               # Seed the database with records
php artisan migrate --seed        # Run migrations and seed database

🔹 Model & Controller

php artisan make:model Post       # Create a model
php artisan make:model Post -m    # Create a model with a migration
php artisan make:controller PostController  # Create a controller
php artisan make:controller PostController --resource  # Create a RESTful resource controller

🔹 Authentication & User Management

php artisan make:migration create_users_table  # Create migration for users table
php artisan make:seeder UserSeeder             # Create a database seeder
php artisan tinker                              # Open an interactive shell
php artisan make:policy PostPolicy             # Create a policy

🔹 Laravel Sanctum (API Authentication)

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate

🔹 Queues & Jobs

php artisan queue:work             # Start queue worker
php artisan queue:restart          # Restart queue workers
php artisan make:job SendEmailJob  # Create a new job

🔹 Custom Artisan Command

If you want to create your own CLI command:

php artisan make:command MyCommand

Then, find it in app/Console/Commands/MyCommand.php and modify its logic.


🚀 Final Notes

  • Run php artisan list to explore more commands.
  • If something doesn’t work, clear caches: php artisan optimize:clear
  • Make sure to run Laravel commands inside your project directory.

Would you like help with a custom Laravel 11 command? 🚀

Leave a Reply

Your email address will not be published. Required fields are marked *