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 listphp artisan help <command> — Show help for a specific command.
php artisan help make:modelphp artisan serve — Start the built-in development server.
php artisan serve --port=8080php artisan tinker — Open an interactive REPL for your application.
php artisan tinkerphp artisan env — Show the current application environment.
php artisan envphp artisan about — Show application overview (Laravel 9+).
php artisan aboutCode Generation (make:)
php artisan make:model <Name> — Create a new Eloquent model.
php artisan make:model Post -mfscphp artisan make:controller <Name> — Create a new controller.
php artisan make:controller PostController --resourcephp artisan make:migration <name> — Create a new database migration.
php artisan make:migration create_posts_tablephp artisan make:seeder <Name> — Create a new database seeder.
php artisan make:seeder PostSeederphp artisan make:middleware <Name> — Create a new middleware class.
php artisan make:middleware CheckAgephp artisan make:request <Name> — Create a new form request validation class.
php artisan make:request StorePostRequestphp artisan make:command <Name> — Create a new Artisan command.
php artisan make:command SendEmailsphp artisan make:job <Name> — Create a new queue job class.
php artisan make:job ProcessPodcastDatabase & Migrations
php artisan migrate — Run pending database migrations. Use with care in production (back up first, requires --force).
php artisan migratephp artisan migrate:status — Show the status of each migration.
php artisan migrate:statusphp artisan migrate:rollback — Roll back the last batch of migrations.
php artisan migrate:rollback --step=2php 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 --seedphp artisan migrate:reset — Roll back all migrations, emptying the schema.
php artisan migrate:resetphp artisan db:seed — Run database seeders.
php artisan db:seed --class=PostSeederphp artisan db:wipe — Drop all tables, views, and types. Destructive: erases the entire database structure – dangerous in production, requires --force.
php artisan db:wipeCache & Config
php artisan cache:clear — Clear the application cache.
php artisan cache:clearphp artisan config:clear — Clear the configuration cache.
php artisan config:clearphp artisan config:cache — Create a configuration cache file (faster loading).
php artisan config:cachephp artisan route:cache — Create a route cache file.
php artisan route:cachephp artisan route:clear — Clear the route cache.
php artisan route:clearphp artisan view:clear — Clear compiled view files.
php artisan view:clearphp artisan optimize:clear — Clear all cached files (config, routes, views, events).
php artisan optimize:clearQueues & Scheduling
php artisan queue:work — Start processing jobs on the queue.
php artisan queue:work --tries=3php artisan queue:listen — Listen for queue jobs (restarts after each job).
php artisan queue:listenphp artisan queue:retry <id> — Retry a failed queue job.
php artisan queue:retry allphp artisan queue:failed — List all failed queue jobs.
php artisan queue:failedphp artisan queue:flush — Delete all failed queue jobs.
php artisan queue:flushphp artisan schedule:run — Run scheduled tasks defined in the kernel.
php artisan schedule:runphp artisan schedule:list — List all scheduled tasks.
php artisan schedule:listRoutes & Maintenance
php artisan route:list — List all registered routes.
php artisan route:list --path=apiphp 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 upphp artisan key:generate — Generate a new application encryption key.
php artisan key:generatephp 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
- Artisan Console – Laravel documentation – official reference for every Artisan command and writing your own
- Database: Migrations – Laravel documentation – background on
migrate,migrate:freshand the destructive commands