Artisan — The Laravel Command Line

Practical guide to Laravel Artisan — generate code, run migrations, manage queues and clear caches straight from the command line.

Artisan is the command line that ships with every Laravel project – you reach it through php artisan. Instead of typing boilerplate by hand, you generate models, controllers and migrations with a single command, drive queues and scheduled tasks, and clear caches whenever your code changes. This guide gathers the commands you actually reach for in day-to-day Laravel work – from your first make: call to keeping a production app in good shape.

General

php artisan list — List all available Artisan commands.

php artisan list

php artisan help <command> — Show help for a specific command.

php artisan help make:model

php artisan serve — Start the built-in development server.

php artisan serve --port=8080

php artisan tinker — Open an interactive REPL for your application.

php artisan tinker

php artisan env — Show the current application environment.

php artisan env

php artisan about — Show application overview (Laravel 9+).

php artisan about

Code Generation (make:)

php artisan make:model <Name> — Create a new Eloquent model.

php artisan make:model Post -mfsc

php artisan make:controller <Name> — Create a new controller.

php artisan make:controller PostController --resource

php artisan make:migration <name> — Create a new database migration.

php artisan make:migration create_posts_table

php artisan make:seeder <Name> — Create a new database seeder.

php artisan make:seeder PostSeeder

php artisan make:middleware <Name> — Create a new middleware class.

php artisan make:middleware CheckAge

php artisan make:request <Name> — Create a new form request validation class.

php artisan make:request StorePostRequest

php artisan make:command <Name> — Create a new Artisan command.

php artisan make:command SendEmails

php artisan make:job <Name> — Create a new queue job class.

php artisan make:job ProcessPodcast

Database & Migrations

php artisan migrate — Run pending database migrations. Use with care in production (back up first, requires --force).

php artisan migrate

php artisan migrate:status — Show the status of each migration.

php artisan migrate:status

php artisan migrate:rollback — Roll back the last batch of migrations.

php artisan migrate:rollback --step=2

php artisan migrate:fresh — Drop all tables and re-run all migrations. Destructive: wipes all data – dangerous in production, only with --force.

php artisan migrate:fresh --seed

php artisan migrate:reset — Roll back all migrations, emptying the schema.

php artisan migrate:reset

php artisan db:seed — Run database seeders.

php artisan db:seed --class=PostSeeder

php artisan db:wipe — Drop all tables, views, and types. Destructive: erases the entire database structure – dangerous in production, requires --force.

php artisan db:wipe

Cache & Config

php artisan cache:clear — Clear the application cache.

php artisan cache:clear

php artisan config:clear — Clear the configuration cache.

php artisan config:clear

php artisan config:cache — Create a configuration cache file (faster loading).

php artisan config:cache

php artisan route:cache — Create a route cache file.

php artisan route:cache

php artisan route:clear — Clear the route cache.

php artisan route:clear

php artisan view:clear — Clear compiled view files.

php artisan view:clear

php artisan optimize:clear — Clear all cached files (config, routes, views, events).

php artisan optimize:clear

Queues & Scheduling

php artisan queue:work — Start processing jobs on the queue.

php artisan queue:work --tries=3

php artisan queue:listen — Listen for queue jobs (restarts after each job).

php artisan queue:listen

php artisan queue:retry <id> — Retry a failed queue job.

php artisan queue:retry all

php artisan queue:failed — List all failed queue jobs.

php artisan queue:failed

php artisan queue:flush — Delete all failed queue jobs.

php artisan queue:flush

php artisan schedule:run — Run scheduled tasks defined in the kernel.

php artisan schedule:run

php artisan schedule:list — List all scheduled tasks.

php artisan schedule:list

Routes & Maintenance

php artisan route:list — List all registered routes.

php artisan route:list --path=api

php artisan down — Put the application into maintenance mode.

php artisan down --secret='bypass-token'

php artisan up — Bring the application out of maintenance mode.

php artisan up

php artisan key:generate — Generate a new application encryption key.

php artisan key:generate

php artisan storage:link — Create a symbolic link from public/storage to storage/app/public.

php artisan storage:link

Conclusion

Artisan takes the repetitive grunt work off your plate and keeps a Laravel project manageable from the first scaffold all the way to deployment – a single entry point for generation, database, queues and maintenance. Treat the destructive commands with respect: migrate:fresh and db:wipe drop every table and all data, and they cause irreparable damage in production if they run by accident. Cache your config and routes in production (config:cache, route:cache), and remember optimize:clear after every change.

Further Reading

  • cargo – build tool and package manager for Rust
  • composer – dependency manager for PHP, the foundation of every Laravel project
  • drush – command line for Drupal sites