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.
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 projectphp artisan servephp artisan make:model Post -mcrphp artisan make:migration create_posts_tablephp artisan make:controller PostControllerphp artisan make:middleware CheckAgephp artisan make:request StorePostRequestphp artisan make:job ProcessPodcastphp artisan make:event PodcastProcessedphp artisan make:listener SendNotificationDatabase 8
php artisan migratephp artisan migrate:freshphp artisan migrate:rollbackphp artisan migrate:statusphp artisan db:seedphp artisan db:seed --class=UserSeederphp artisan make:seeder UserSeederphp artisan make:factory PostFactoryRoutes & Cache 9
php artisan route:listphp artisan route:cachephp artisan route:clearphp artisan config:cachephp artisan config:clearphp artisan view:cachephp artisan view:clearphp artisan optimizephp artisan optimize:clearQueues & Jobs 7
php artisan queue:workphp artisan queue:work --queue=high,defaultphp artisan queue:restartphp artisan queue:failedphp artisan queue:retry <id>php artisan queue:flushphp artisan make:job ProcessPodcastTesting & Debug 6
php artisan testphp artisan test --filter=UserTestphp artisan tinkerphp artisan downphp artisan upphp artisan storage:linkParameter matrix
| Parameter | Effect | Example |
|---|---|---|
laravel new project | Create a new project skeleton (via the create-project flow); more complete than cloning a template by hand | laravel new project |
php artisan serve | Start the built-in dev server; this is a development server, not suitable as a production process | php artisan serve |
make:model Post -mcr | Generate a model in one shot (-m migration, -c controller, -r resource controller); the most frequently used generator | php artisan make:model Post -mcr |
make:migration create_posts_table | Create only a migration file; naming must be create_xxx_table, otherwise rollback cannot find the table | php artisan make:migration create_posts_table |
make:controller PostController | Generate a controller; with --invokable it can generate a single-action controller | php artisan make:controller PostController |
make:middleware CheckAge | Generate middleware; it only takes effect once registered in the Kernel or bootstrap middleware stack | php artisan make:middleware CheckAge |
make:request StorePostRequest | Generate a form request class to separate validation and authorization from the controller | php artisan make:request StorePostRequest |
make:job ProcessPodcast | Generate a queue job class; the job must be safe to retry and cannot assume it runs only once | php artisan make:job ProcessPodcast |
make:event / make:listener | Generate events and listeners, the standard pairing for event-driven decoupling | php artisan make:listener SendNotification |
php artisan migrate | Run migrations that have not run yet; --force skips the confirmation prompt in production | php artisan migrate |
php artisan migrate:fresh | Roll back everything and rebuild, wiping all table data; misuse in production is a data incident | php artisan migrate:fresh |
php artisan migrate:rollback | Roll back the most recent batch of migrations, commonly used locally to undo a migration you just wrote | php artisan migrate:rollback |
php artisan migrate:status | List whether each migration has run; the first step in diagnosing a table that was not created | php artisan migrate:status |
php artisan db:seed --class=UserSeeder | Specify the Seeder class to run; use --class to avoid accidentally running the wrong seeder among many | php artisan db:seed --class=UserSeeder |
php artisan make:factory PostFactory | Generate a model factory, used to fake data in tests; its purpose differs from a seeder | php artisan make:factory PostFactory |
php artisan route:list | List all routes and middleware; the go-to command for diagnosing 404s and missing middleware | php artisan route:list |
php artisan route:cache | Cache the route table for a big speedup; route files can no longer contain closure routes | php artisan route:cache |
php artisan config:cache | Cache configuration; afterwards env() cannot read values at runtime (config is frozen into constants) | php artisan config:cache |
php artisan optimize | Generate route, config and view caches in one go; the standard post-deployment action | php artisan optimize |
php artisan optimize:clear | Clear all caches; run this first when a local .env change does not take effect | php artisan optimize:clear |
php artisan view:cache / view:clear | Precompile views / clear the view cache; clear once when a Blade change does not take effect | php artisan view:clear |
php artisan queue:work | Run the queue consumer in the foreground, processing jobs one by one; use this in development to see errors | php artisan queue:work |
php artisan queue:work --queue=high,default | Set queue priority, consuming in comma order; configuring a high-priority queue without this argument processes jobs serially | php artisan queue:work --queue=high,default |
php artisan queue:restart | Make running workers exit gracefully and restart when they next fetch a job; a necessary step when releasing new code | php artisan queue:restart |
php artisan queue:failed | List failed jobs and their exceptions; the entry point for troubleshooting | php artisan queue:failed |
php artisan queue:retry <id> | Retry the specified failed job; also supports flush to clear all failure records | php artisan queue:retry <id> |
php artisan queue:flush | Clear all failed job records; irreversible, and misuse loses your troubleshooting clues | php artisan queue:flush |
php artisan test | Run the test suite; --filter runs only a single test class | php artisan test --filter=UserTest |
php artisan tinker | Enter a REPL with the framework already booted, useful to verify models, queries and relationships behave as expected | php artisan tinker |
php artisan down / up | Maintenance mode toggle; down returns 503 for all requests, so be sure to set --retry and --secret | php artisan down |
php artisan storage:link | Create the public/storage symlink; without it uploaded images cannot be accessed by URL | php 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
1Confirm whether each migration has run
php artisan migrate:statusThe first step for table-not-found problems.
2Check whether the route is actually registered
php artisan route:listOn a 404, first confirm the route exists, then check whether the path and method match.
3Clear all caches
php artisan optimize:clearRun this first when a change to .env, routes or views does not take effect.
4Make the queue worker load new code
php artisan queue:restartA necessary step after releasing new code.
5Inspect failed jobs and exception details
php artisan queue:failedLook at the exception type first before deciding to retry or change code.
6Run a single test class only
php artisan test --filter=UserTestShortens 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:clearA 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 optimizeconfig: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:rollbackIn 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