Mastering Artisan: 15 Commands Every Laravel Newbie Should Know

Author

Kritim Yantra

Apr 09, 2025

Mastering Artisan: 15 Commands Every Laravel Newbie Should Know

Laravel's Artisan CLI is your Swiss Army knife for development. These commands will supercharge your workflow whether you're building your first app or working on enterprise projects. Here are the 15 most essential commands every Laravel developer should memorize.


1. Create a New Laravel Project

Start fresh with a clean installation:

laravel new project-name

Or with Composer:

composer create-project laravel/laravel project-name

Pro Tip: Add --jet for Inertia/React/Vue scaffolding or --dev for the latest dev version.


2. Run the Development Server

Launch your application locally:

php artisan serve

Customize port:

php artisan serve --port=8080

3. Generate a Controller

Create controller files instantly:

php artisan make:controller PostController

Need API methods? Add --api:

php artisan make:controller PostController --api

4. Create a Model with Migration

Generate a model and its database migration together:

php artisan make:model Post -m

The -m flag creates a migration file in database/migrations.


5. Run Database Migrations

Execute pending migrations:

php artisan migrate

Rollback the last batch:

php artisan migrate:rollback

Danger Zone: Completely reset your database (development only!):

php artisan migrate:fresh

6. Create a Database Seeder

Generate test data easily:

php artisan make:seeder PostsTableSeeder

Run all seeders:

php artisan db:seed

Or specific ones:

php artisan db:seed --class=PostsTableSeeder

7. Generate a Middleware

Create custom request filters:

php artisan make:middleware AdminMiddleware

Register it in app/Http/Kernel.php.


8. List All Routes

View your application's route list:

php artisan route:list

Filter routes:

php artisan route:list --method=GET

9. Create a Job

For queueable tasks:

php artisan make:job ProcessPodcast

Dispatch jobs from controllers to handle time-consuming tasks asynchronously.


10. Clear Application Cache

Fix when things get weird:

php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear

Nuclear option (clears all caches):

php artisan optimize:clear

11. Generate Authentication Scaffolding

Laravel Breeze (recommended):

composer require laravel/breeze --dev
php artisan breeze:install
npm install && npm run dev
php artisan migrate

Laravel UI (legacy):

composer require laravel/ui
php artisan ui vue --auth

12. Create a Custom Artisan Command

Build your own CLI tools:

php artisan make:command BackupDatabase

Edit the generated file in app/Console/Commands.


13. Tinker with Your App

Interactive PHP shell for debugging:

php artisan tinker

Try queries instantly:

>>> User::find(1)
>>> factory(App\User::class)->make()

14. Generate Notifications

Create notification classes:

php artisan make:notification InvoicePaid

Send via email, SMS (Nexmo/Vonage), Slack, etc.


15. Schedule Tasks

Edit the scheduler (runs via cron):

php artisan schedule:run

Define jobs in app/Console/Kernel.php:

$schedule->command('inspire')->hourly();

Bonus: Essential Shortcuts

  1. Quick Model Creation
    -a flag creates controller, migration, factory, and seeder:

    php artisan make:model Post -a
    
  2. Environment Management
    Cache your config (production only):

    php artisan config:cache
    
  3. Storage Link
    Link public storage:

    php artisan storage:link
    

When Things Go Wrong

  • Undefined variable errors? php artisan view:clear
  • Route not found? php artisan route:clear
  • Class not found? composer dump-autoload

Conclusion

Master these 15 commands and you'll:
✅ Build features faster
✅ Debug efficiently
✅ Manage databases like a pro
✅ Automate repetitive tasks

Next Steps:

  1. Explore php artisan list for all available commands
  2. Create custom commands for your project-specific tasks
  3. Learn command signatures and options with php artisan help [command]

🚀 You're now an Artisan power user! What command will you try first? Drop it in the comments! 👇

Tags

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts