Skip to main content
Artisan Console

Artisan Console

Artisan is Laravel's command-line interface. It runs migrations, clears caches, generates classes, starts queue workers, and executes your own commands. Run php artisan to see every command available.

Common commands

php artisan serve
php artisan migrate
php artisan migrate:rollback
php artisan db:seed
php artisan optimize
php artisan optimize:clear
php artisan route:list
php artisan queue:work
php artisan schedule:work
php artisan test

Generators

php artisan make:controller PostController --resource
php artisan make:model Post -mfsc
php artisan make:request StorePostRequest
php artisan make:middleware EnsureTeamIsActive
php artisan make:policy PostPolicy --model=Post
php artisan make:job SendInvoice
php artisan make:command PruneDrafts

Most generators accept --help to list options. Generated files include the correct namespace and boilerplate.

Tinker

Tinker is an interactive shell with the application booted. It is useful for inspecting models and testing a query, but it is not a substitute for tests.

php artisan tinker
>>> User::count()
>>> Post::latest()->first()->title

Inspecting the application

php artisan about
php artisan route:list --path=api
php artisan event:list
php artisan schedule:list
php artisan config:show services

Maintenance mode

php artisan down --secret="preview-token"
php artisan up

While down, visitors receive a 503 page. A secret lets the team preview the site through a special URL.

Environment awareness

Destructive commands such as migrate:fresh drop tables. Laravel asks for confirmation in production. Do not bypass those prompts in deployment scripts unless the script has its own safeguards.

php artisan migrate --force
php artisan migrate:fresh --seed   # local development only

Custom commands

Application-specific commands are registered automatically when placed in app/Console/Commands. The next chapter covers writing them.