[!WARNING] This content is AI-generated. Verify before relying on it.

Common Artisan Commands

Artisan is the command-line interface included with Laravel. It provides commands for generating boilerplate, running database migrations, managing caches, and inspecting application state.

Make / Generator Commands

Creating Models

CommandDescription
php artisan make:model PostCreates a basic Eloquent model
php artisan make:model Post -mModel + migration
php artisan make:model Post -cModel + controller
php artisan make:model Post -crModel + resource controller
php artisan make:model Post -mcrModel + migration + resource controller
php artisan make:model Post -sModel + seeder
php artisan make:model Post -fModel + factory
php artisan make:model Post -aModel + migration + factory + seeder + policy + resource controller + form requests (--all)
php artisan make:model RoleUser --pivotCreates a custom pivot model

Creating Controllers

CommandDescription
php artisan make:controller PostControllerBasic empty controller
php artisan make:controller PostController --resourceController with CRUD actions (index, create, store, show, edit, update, destroy)
php artisan make:controller PostController --resource --model=PostResource controller with typed model route-binding
php artisan make:controller Api/PostController --apiAPI resource controller (omits HTML create and edit methods)
php artisan make:controller ProvisionServer --invokableSingle action controller with __invoke()

Creating Other Core Classes

CommandDescription
php artisan make:migration create_posts_tableGenerates a new migration file
php artisan make:request StorePostRequestGenerates a Form Request validation class
php artisan make:policy PostPolicy --model=PostGenerates a Policy class mapped to a model
php artisan make:mail WelcomeUserGenerates a Mailable class
php artisan make:mail OrderShipped --markdown=emails.orders.shippedMailable with a Markdown Blade template
php artisan make:seeder PostSeederGenerates a database seeder
php artisan make:factory PostFactory --model=PostGenerates a model factory
php artisan make:middleware EnsureTokenIsValidGenerates custom HTTP middleware
php artisan make:job ProcessPodcastGenerates a queueable job

Database Migrations & Seeding

CommandDescription
php artisan migrateRun pending migrations
php artisan migrate:statusShow migration execution status and batches
php artisan migrate:rollbackRollback the last migration batch
php artisan migrate:rollback --step=2Rollback the last 2 migrations
php artisan migrate:resetRollback all database migrations
php artisan migrate:refreshRollback all migrations and run them again
php artisan migrate:refresh --seedRollback all, re-run, and seed database
php artisan migrate:freshDrop all tables and execute all migrations from scratch
php artisan migrate:fresh --seedDrop all tables, run all migrations, and run seeders
php artisan db:seedRun the root DatabaseSeeder
php artisan db:seed --class=UserSeederRun a specific seeder class

[!CAUTION] Never run migrate:fresh in production. It drops all tables and destroys data permanently.


Optimization & Caching

Use caching in production to boost performance by eliminating runtime file scanning and route parsing.

CommandDescription
php artisan optimizeCaches bootstrap files, configuration, and routes
php artisan optimize:clearClears all cached bootstrap files, config, routes, views, and events
php artisan route:cacheCompiles all routes into a single cached file
php artisan route:clearDeletes the compiled route cache
php artisan config:cacheMerges all config files into a single cached file
php artisan config:clearDeletes the compiled configuration cache
php artisan view:cachePre-compiles all Blade templates
php artisan view:clearClears compiled Blade view files
php artisan cache:clearFlushes the application data cache (Redis/Memcached/file)
php artisan event:cacheCaches discovered events and listeners
php artisan event:clearClears the event cache

[!TIP] During local development, run php artisan optimize:clear if route or configuration changes fail to reflect.


Routing & Inspection

CommandDescription
php artisan route:listLists all registered application routes
php artisan route:list --path=apiFilters routes by URI path
php artisan route:list --except-vendorExcludes vendor-registered routes
php artisan aboutDisplays environment, PHP version, cache drivers, and framework details

Development & Maintenance

CommandDescription
php artisan serveStarts local PHP development server (http://127.0.0.1:8000)
php artisan serve --port=8080Starts server on a specified port
php artisan tinkerInteractive REPL shell powered by PsySH
php artisan downPuts the application into maintenance mode
php artisan down --secret="bypass-token"Enables maintenance mode with a bypass cookie
php artisan upBrings the application out of maintenance mode
php artisan queue:workStarts processing queued jobs
php artisan schedule:workRuns the task scheduler locally (daemon mode for local dev)