Laravel Cheatsheet - Laravel Artisan Command Reference

This reference is for developers building Laravel applications and the people deploying them, centering on Artisan, the CLI you run constantly. It covers scaffolding a project, generating models/controllers/migrations, running and rolling back migrations, boosting production with route/config/view caching, and handling background work with the queue. Unlike a generic Artisan command dump, entries are grouped by the workflow you actually repeat: create feature → migrate DB → run locally → cache for prod → queue the heavy work. After reading, you should be able to scaffold a CRUD feature, apply and roll back migrations cleanly, and be confident about what each cache command commits or clears.

Languages·40 commands·Last updated 2026-07-21
laravelphpframework

Typical Use Case

For backend engineers running the usual Laravel pipeline: scaffold a skeleton, run the migration, wire the route, start the queue. Artisan is useful because each command both creates the file and registers the convention, so make:model -mcr produces a model, migration, controller and resource controller at once. Covers code generation, migrations, routing, cache commands, queue workers and maintenance mode. Two conventions: the filename sets the class name, and cached config locks the env value.

Project & Dev 10

laravel new project
Create a new project
php artisan serve
Start the dev server
php artisan make:model Post -mcr
Make model+migration+controller
php artisan make:migration create_posts_table
Create a migration
php artisan make:controller PostController
Create a controller
php artisan make:middleware CheckAge
Create middleware
php artisan make:request StorePostRequest
Create a form request
php artisan make:job ProcessPodcast
Create a queue job
php artisan make:event PodcastProcessed
Create an event
php artisan make:listener SendNotification
Create a listener

Database 8

php artisan migrate
Run migrations
php artisan migrate:fresh
Fresh: drop all and re-migrate
php artisan migrate:rollback
Rollback last migration
php artisan migrate:status
View migration status
php artisan db:seed
Run seeders
php artisan db:seed --class=UserSeeder
Run a specific seeder
php artisan make:seeder UserSeeder
Create a seeder
php artisan make:factory PostFactory
Create a factory

Routes & Cache 9

php artisan route:list
List all routes
php artisan route:cache
Cache routes (prod)
php artisan route:clear
Clear route cache
php artisan config:cache
Cache config
php artisan config:clear
Clear config cache
php artisan view:cache
Cache views
php artisan view:clear
Clear view cache
php artisan optimize
Optimize (config + routes)
php artisan optimize:clear
Clear all caches

Queues & Jobs 7

php artisan queue:work
Start the queue worker
php artisan queue:work --queue=high,default
Set queue priority
php artisan queue:restart
Restart all workers
php artisan queue:failed
List failed jobs
php artisan queue:retry <id>
Retry a failed job
php artisan queue:flush
Flush all failed jobs
php artisan make:job ProcessPodcast
Create a job class

Testing & Debug 6

php artisan test
Run tests
php artisan test --filter=UserTest
Run a specific test
php artisan tinker
Enter the REPL (tinker)
php artisan down
Enter maintenance mode
php artisan up
Exit maintenance mode
php artisan storage:link
Link the storage dir

Parameter matrix

ParameterEffectExample
laravel new projectCreate a new project skeleton (via the create-project flow); more complete than cloning a template by handlaravel new project
php artisan serveStart the built-in dev server; this is a development server, not suitable as a production processphp artisan serve
make:model Post -mcrGenerate a model in one shot (-m migration, -c controller, -r resource controller); the most frequently used generatorphp artisan make:model Post -mcr
make:migration create_posts_tableCreate only a migration file; naming must be create_xxx_table, otherwise rollback cannot find the tablephp artisan make:migration create_posts_table
make:controller PostControllerGenerate a controller; with --invokable it can generate a single-action controllerphp artisan make:controller PostController
make:middleware CheckAgeGenerate middleware; it only takes effect once registered in the Kernel or bootstrap middleware stackphp artisan make:middleware CheckAge
make:request StorePostRequestGenerate a form request class to separate validation and authorization from the controllerphp artisan make:request StorePostRequest
make:job ProcessPodcastGenerate a queue job class; the job must be safe to retry and cannot assume it runs only oncephp artisan make:job ProcessPodcast
make:event / make:listenerGenerate events and listeners, the standard pairing for event-driven decouplingphp artisan make:listener SendNotification
php artisan migrateRun migrations that have not run yet; --force skips the confirmation prompt in productionphp artisan migrate
php artisan migrate:freshRoll back everything and rebuild, wiping all table data; misuse in production is a data incidentphp artisan migrate:fresh
php artisan migrate:rollbackRoll back the most recent batch of migrations, commonly used locally to undo a migration you just wrotephp artisan migrate:rollback
php artisan migrate:statusList whether each migration has run; the first step in diagnosing a table that was not createdphp artisan migrate:status
php artisan db:seed --class=UserSeederSpecify the Seeder class to run; use --class to avoid accidentally running the wrong seeder among manyphp artisan db:seed --class=UserSeeder
php artisan make:factory PostFactoryGenerate a model factory, used to fake data in tests; its purpose differs from a seederphp artisan make:factory PostFactory
php artisan route:listList all routes and middleware; the go-to command for diagnosing 404s and missing middlewarephp artisan route:list
php artisan route:cacheCache the route table for a big speedup; route files can no longer contain closure routesphp artisan route:cache
php artisan config:cacheCache configuration; afterwards env() cannot read values at runtime (config is frozen into constants)php artisan config:cache
php artisan optimizeGenerate route, config and view caches in one go; the standard post-deployment actionphp artisan optimize
php artisan optimize:clearClear all caches; run this first when a local .env change does not take effectphp artisan optimize:clear
php artisan view:cache / view:clearPrecompile views / clear the view cache; clear once when a Blade change does not take effectphp artisan view:clear
php artisan queue:workRun the queue consumer in the foreground, processing jobs one by one; use this in development to see errorsphp artisan queue:work
php artisan queue:work --queue=high,defaultSet queue priority, consuming in comma order; configuring a high-priority queue without this argument processes jobs seriallyphp artisan queue:work --queue=high,default
php artisan queue:restartMake running workers exit gracefully and restart when they next fetch a job; a necessary step when releasing new codephp artisan queue:restart
php artisan queue:failedList failed jobs and their exceptions; the entry point for troubleshootingphp artisan queue:failed
php artisan queue:retry <id>Retry the specified failed job; also supports flush to clear all failure recordsphp artisan queue:retry <id>
php artisan queue:flushClear all failed job records; irreversible, and misuse loses your troubleshooting cluesphp artisan queue:flush
php artisan testRun the test suite; --filter runs only a single test classphp artisan test --filter=UserTest
php artisan tinkerEnter a REPL with the framework already booted, useful to verify models, queries and relationships behave as expectedphp artisan tinker
php artisan down / upMaintenance mode toggle; down returns 503 for all requests, so be sure to set --retry and --secretphp artisan down
php artisan storage:linkCreate the public/storage symlink; without it uploaded images cannot be accessed by URLphp artisan storage:link

Common pitfalls

SymptomYou changed a setting in .env, but the code still reads the old value.

CauseThe configuration was frozen by config:cache, so .env is no longer parsed at runtime.

FixRun php artisan optimize:clear in development; after changing config in production, run config:cache again.

SymptomNew code was deployed to production, but the queue still runs the old logic.

CauseThe long-running queue:work process has already loaded the code into memory and does not update itself.

FixRun queue:restart in your deployment pipeline so workers restart gracefully, and confirm the process manager will bring them back up.

SymptomAfter route:cache it reports "Unable to prepare route ... uses Closure" and all routes break.

CauseThere are closure routes in the route files, and closures cannot be serialized into the cache.

FixRewrite closure routes as controller class actions; in development use route:clear to drop the cache and keep debugging.

Symptommigrate:fresh was run in production by mistake and all table data is gone.

Causefresh drops all tables and rebuilds them, with no confirmation and no backup step.

FixOnly allow migrate in production; back up the database first and restrict the use of fresh in non-interactive environments as a process safeguard.

SymptomThe uploaded file saves successfully, but its URL returns 404.

CauseThe public/storage symlink does not exist, or shared hosting does not allow creating symlinks.

FixRun storage:link; when a link cannot be created, add a route to a controller that returns the file instead.

SymptomJobs on the high-priority queue are not processed for a long time.

CauseThe worker was not started with --queue=high,default, or the queue name used in dispatch does not match the configuration.

FixList the full queue order by priority, and check that the queue name used in dispatch matches the startup arguments in the process manager.

SymptomThe file created by make:migration does not match the table name, and rollback reports the migration not found.

CauseManual naming did not follow the naming convention of the framework, or repeated generation scrambled the rollback order within a batch.

FixConsistently name with create_xxx_table / add_xxx_to_yyy_table, and use migrate:status to confirm the execution records.

SymptomAll requests return 503 and you forgot maintenance mode is on.

Causeup was not run after php artisan down, leaving maintenance mode entered during an incident still enabled.

FixRun php artisan up; when running down, include --retry=60 so clients retry automatically.

Troubleshooting

  1. 1Confirm whether each migration has run

    php artisan migrate:status

    The first step for table-not-found problems.

  2. 2Check whether the route is actually registered

    php artisan route:list

    On a 404, first confirm the route exists, then check whether the path and method match.

  3. 3Clear all caches

    php artisan optimize:clear

    Run this first when a change to .env, routes or views does not take effect.

  4. 4Make the queue worker load new code

    php artisan queue:restart

    A necessary step after releasing new code.

  5. 5Inspect failed jobs and exception details

    php artisan queue:failed

    Look at the exception type first before deciding to retry or change code.

  6. 6Run a single test class only

    php artisan test --filter=UserTest

    Shortens the feedback loop and confirms the test environment config is correct.

Command Examples

Scaffold a model with migration, controller, and form request

php artisan make:model Post -mcr php artisan make:request StorePostRequest php artisan migrate

-m makes the migration, -c the controller, -r the form request — but fields, validation rules, and authorization still need writing. The form request is worth it because a failed validation returns a 302 with the error bag automatically, saving the controller from error-handling boilerplate.

Debugging 404s and 405s: list the routes first

php artisan route:list php artisan route:list --path=posts php artisan route:clear

A 405 means the route exists but the method does not match (usually a POST against a GET-only route); a 404 means the path or prefix is wrong. If an edited route file still shows old behaviour, route:cache is serving the old table — clear it, then retest.

Changed .env and nothing happened: walk the cache

php artisan config:clear php artisan route:clear php artisan view:clear // Bake the caches back before going live php artisan optimize

config:cache bakes the .env values into a static file, after which editing .env does nothing — the single most common cause of "my config change had no effect". Always config:clear after editing .env, then run optimize before deploying to bake everything back in.

Queues: priority order plus graceful restart

php artisan queue:work --queue=high,default php artisan queue:restart php artisan queue:failed php artisan queue:retry <id>

A worker is a long-running process holding the code loaded at start; deploy without a restart and jobs keep running the old logic with no warning. queue:restart makes workers finish the current job and exit to reload. Never queue:flush before reading queue:failed to understand why.

Migration order around a deploy: check status first

php artisan migrate:status php artisan migrate php artisan migrate:rollback

In production, deploy code that tolerates the old schema first, then migrate — adding a NOT NULL column while the previous release is still serving traffic breaks those writes. rollback reverses only the latest batch and is far safer than hand-editing tables. migrate:fresh drops and rebuilds the database: development and tests only.

Common Pitfalls

  • config:cache bakes .env into a static file; after that, editing .env has no effect until config:clear. Most unexplained "my config change did nothing" cases come from here.
  • migrate:fresh rolls back every migration and re-runs them, which is a database drop and rebuild. Running it against production or any real data is irreversible loss with no confirmation prompt.
  • Once queue:work runs as a long-lived process, deploying without a restart leaves workers executing the old code — behaviour diverges from expectations with nothing in the logs. Make queue:restart part of the deploy.
  • route:cache serves a cached route table; deploying new code against a stale cache yields half-old, half-new controller behaviour. Confirm the cache is cleared before adding routes in production.
  • After php artisan down, forgetting php artisan up leaves the site returning 503 indefinitely. Before leaving maintenance mode, verify the APP_ENV and cache state in .env are back to normal.
  • queue:flush deletes every failed-job record. Run queue:failed first to keep the failure reasons, or you discard the only clue about what broke.

Tips

  • In production always run php artisan optimize to cache config and routes.
  • make:model -mcr generates model+migration+resource controller at once.
  • Run queue workers under Supervisor to avoid unexpected exits.

FAQ

My production behaviour is stale after editing .env or routes — which caches must I clear?

Laravel compiles config and routes into files, so source edits have no effect until you drop those caches. After changing .env run php artisan config:clear, then php artisan route:clear to force route re-parsing; if templates misbehave use php artisan view:clear to drop the compiled Blade files. Before going live, php artisan optimize bakes config and route caches together for performance, and php artisan optimize:clear wipes them all when rolling back or returning to debugging. A stale config cache after editing .env is one of the most common local-development confusions.

I broke a migration file — how do I step back or rebuild the database?

There are two levels. php artisan migrate:rollback undoes the most recent batch, which is the right move when a migration was wrong. php artisan migrate:fresh rolls everything back and re-runs all migrations, effectively rebuilding every table — handy in development and test environments for a fast reset, but it destroys all data. To find out why a table never appeared, check php artisan migrate:status first; it lists every migration as pending or ran. For seeding, php artisan db:seed fills the database and php artisan db:seed --class=UserSeeder runs a single seeder class.

A queued job failed — how do I diagnose and retry it?

Inspect the failure list first: php artisan queue:failed prints failed jobs with their causes, and the logs tell you whether it was a business exception or a timeout. Re-queue one with php artisan queue:retry <id> once the logic is fixed, and clear the backlog with php artisan queue:flush when nothing needs retrying. Consume by priority with php artisan queue:work --queue=high,default, which drains high before falling back to default so important work lands first. After deploying new code run php artisan queue:restart so workers pick it up once they finish the current job, and in production keep a supervisor-style process manager watching the worker.

Which artisan generator flag combinations save the most time?

The workhorse is php artisan make:model Post -mcr: -m for the migration, -c for a resource controller and -r for the Form Request, scaffolding the model and its companions in one shot. Narrower alternatives: php artisan make:migration create_posts_table when you only need the migration, php artisan make:controller PostController for just a controller. Pull validation into its own class with php artisan make:request StorePostRequest, and handle auth or age gates with php artisan make:middleware CheckAge. Asynchronous and event-driven skeletons come from php artisan make:job ProcessPodcast, php artisan make:event PodcastProcessed and php artisan make:listener SendNotification, while php artisan make:factory PostFactory pairs with faker to bulk-generate model fixtures.

An endpoint returns 404 or 405 — which command pins it down?

php artisan route:list prints every registered route with its controller method; if the method does not match, the route was never registered or the path is wrong. Seeing the same path listed twice means the later registration wins, which shows up as "I changed the route but the old behaviour persists". A 405 means the route exists but the HTTP verb does not — check the method column in route:list for a POST route that was called with GET. Day to day you serve the app with php artisan serve, poke at logic in the php artisan tinker REPL, and narrow the suite with php artisan test --filter=UserTest; php artisan down and php artisan up control the maintenance window.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us