agyanadda@gmail.com

Laravel Artisan Commands

Laravel Basics 1 min read Updated Dec 2, 2026 Topic 7 of 31

Artisan is Laravel's command-line tool. Run it from the project folder with php artisan <command>.

Generate files

  • php artisan make:model Post -mcr — model + migration, controller and resource methods in one go
  • make:controller, make:migration, make:request, make:middleware, make:seeder, make:mail, make:job

Everyday commands

  • php artisan list — every available command
  • php artisan route:list — all routes
  • php artisan migrate — run migrations
  • php artisan tinker — an interactive PHP shell with your app loaded, great for testing queries
  • php artisan storage:link — make uploaded files public
  • php artisan key:generate — set APP_KEY in .env

Clearing caches

When a change does not appear, run php artisan optimize:clear. It clears the config, route, view and application caches.

Maintenance mode

php artisan down shows a "Service Unavailable" page to visitors while you update; php artisan up brings the site back.

Add --help to any command to see its options, e.g. php artisan make:model --help.

Example

Example — Generate a full set of files and test in Tinker Bash
# Model + migration + resource controller
php artisan make:model Post -mcr
#  INFO  Model [app/Models/Post.php] created successfully.
#  INFO  Migration [database/migrations/..._create_posts_table.php] created successfully.
#  INFO  Controller [app/Http/Controllers/PostController.php] created successfully.

# Try Eloquent queries interactively
php artisan tinker
> App\Models\User::count()
= 3
> exit

# Something not updating? Clear all caches
php artisan optimize:clear

-mcr means -m (migration), -c (controller) and -r (resource methods). Tinker runs PHP code against your real database, so be careful with delete() there.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which command opens an interactive shell with your Laravel app loaded?

Exercise 2 True / False

php artisan down puts the site into maintenance mode.

Exercise 3 Fill in the Blank

php artisan ___:clear clears the config, route and view caches together.

Frequently Asked Questions

Yes. Run php artisan make:command SendReport, set its $signature (for example 'report:send') and write the logic in handle(). It then runs with php artisan report:send and can be scheduled.