# Artisan — The Laravel Command Line

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

Source: https://www.jpkc.com/db/en/cheatsheets/build-languages/artisan/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## General

`php artisan list` — List all available Artisan commands.

```bash
php artisan list
```

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

```bash
php artisan help make:model
```

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

```bash
php artisan serve --port=8080
```

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

```bash
php artisan tinker
```

`php artisan env` — Show the current application environment.

```bash
php artisan env
```

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

```bash
php artisan about
```

## Code Generation (make:)

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

```bash
php artisan make:model Post -mfsc
```

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

```bash
php artisan make:controller PostController --resource
```

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

```bash
php artisan make:migration create_posts_table
```

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

```bash
php artisan make:seeder PostSeeder
```

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

```bash
php artisan make:middleware CheckAge
```

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

```bash
php artisan make:request StorePostRequest
```

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

```bash
php artisan make:command SendEmails
```

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

```bash
php artisan make:job ProcessPodcast
```

## Database & Migrations

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

```bash
php artisan migrate
```

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

```bash
php artisan migrate:status
```

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

```bash
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`.

```bash
php artisan migrate:fresh --seed
```

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

```bash
php artisan migrate:reset
```

`php artisan db:seed` — Run database seeders.

```bash
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`.

```bash
php artisan db:wipe
```

## Cache & Config

`php artisan cache:clear` — Clear the application cache.

```bash
php artisan cache:clear
```

`php artisan config:clear` — Clear the configuration cache.

```bash
php artisan config:clear
```

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

```bash
php artisan config:cache
```

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

```bash
php artisan route:cache
```

`php artisan route:clear` — Clear the route cache.

```bash
php artisan route:clear
```

`php artisan view:clear` — Clear compiled view files.

```bash
php artisan view:clear
```

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

```bash
php artisan optimize:clear
```

## Queues & Scheduling

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

```bash
php artisan queue:work --tries=3
```

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

```bash
php artisan queue:listen
```

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

```bash
php artisan queue:retry all
```

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

```bash
php artisan queue:failed
```

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

```bash
php artisan queue:flush
```

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

```bash
php artisan schedule:run
```

`php artisan schedule:list` — List all scheduled tasks.

```bash
php artisan schedule:list
```

## Routes & Maintenance

`php artisan route:list` — List all registered routes.

```bash
php artisan route:list --path=api
```

`php artisan down` — Put the application into maintenance mode.

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

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

```bash
php artisan up
```

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

```bash
php artisan key:generate
```

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

```bash
php artisan storage:link
```

<!-- PROSE:outro -->
## 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](https://laravel.com/docs/artisan) – official reference for every Artisan command and writing your own
- [Database: Migrations – Laravel documentation](https://laravel.com/docs/migrations) – background on `migrate`, `migrate:fresh` and the destructive commands
<!-- PROSE:outro:end -->

## Related Commands

- [cargo](https://www.jpkc.com/db/en/cheatsheets/build-languages/cargo/) – build tool and package manager for Rust
- [composer](https://www.jpkc.com/db/en/cheatsheets/build-languages/composer/) – dependency manager for PHP, the foundation of every Laravel project
- [drush](https://www.jpkc.com/db/en/cheatsheets/build-languages/drush/) – command line for Drupal sites

