Back to portfolio Published Dec 26, 2025

Post

The Most Useful Laravel Commands: Artisan, NPM, and Vite Explained

Laravel Tips

Laravel Commands & Tips: Essential Artisan, NPM, and Vite Commands for Faster Development

Laravel is packed with powerful tooling, but knowing which commands to use — and when — is what really speeds up development. This guide covers the most useful Laravel Artisan commands, frontend asset commands using NPM and Vite, and practical Laravel tips I use daily when building production apps with Laravel.

Whether you’re new to Laravel or looking to tighten your workflow, this is a solid command reference to bookmark.

Laravel Artisan Commands You Should Know

Start the Laravel development server

php artisan serve

Starts a local development server at http://127.0.0.1:8000. Ideal for quick local testing.

Clear Laravel caches (fixes most “why is this broken?” issues)

php artisan optimize:clear

Clears:

  • Application cache
  • Config cache
  • Route cache
  • Compiled views

💡 If something isn’t updating, run this first.

Optimise Laravel for production

php artisan optimize

Caches config, routes, and views for improved performance in production environments.

Laravel Database & Migration Commands

Run database migrations

php artisan migrate

Applies all pending migrations.

Roll back the last migration batch

php artisan migrate:rollback

Useful when a migration goes wrong and needs correcting.

Rebuild the database (development only)

php artisan migrate:fresh

Drops all tables and re-runs migrations. Never run this on production.

Seed the database

php artisan db:seed

Or migrate and seed in one step:

php artisan migrate --seed

Laravel Frontend Asset Commands (NPM, Vite & Tailwind)

Modern Laravel projects use Vite to handle frontend assets such as Tailwind CSS and JavaScript.

Install frontend dependencies

npm install

Run this after cloning a Laravel project or pulling new dependencies.

Run Laravel Vite in development mode

npm run dev

This command:

  • Compiles assets
  • Watches for file changes
  • Enables hot module replacement (HMR)
  • You’ll use this constantly during development.
  • Build Laravel assets for production

npm run build

Creates optimised, versioned assets for production deployment.

⚠️ Always run this before deploying to a live server (or in CI).

Common Laravel asset issue fix

If CSS or JS isn’t updating:

npm run dev
php artisan optimize:clear

This resolves most frontend-related caching problems.

Laravel Testing & Debugging Commands

Run all tests

php artisan test

Run a specific test file

php artisan test tests/Feature/AuthTest.php

Speeds up feedback when working on a single feature.

Laravel Tinker (interactive REPL)

php artisan tinker

Test logic and inspect data quickly:

User::count();
Order::latest()->first();

Tinker is one of the fastest ways to debug or explore your application.

Laravel Code Generation Commands

Generate a model with everything included

php artisan make:model Post -mfs

Creates:

  • Model
  • Migration
  • Factory
  • Seeder

Huge productivity win when scaffolding features.

Create a resource controller

php artisan make:controller PostController --resource

Includes all standard REST methods (index, store, update, etc.).

Create a form request

php artisan make:request StorePostRequest

Keeps validation logic clean and reusable.

Laravel Performance & Production Commands

Cache configuration

php artisan config:cache

Cache routes

php artisan route:cache

⚠️ Avoid route caching if your app relies heavily on route closures.

Laravel Tips & Tricks That Save Time

Use route:list to debug routing issues

php artisan route:list

Filter results:

php artisan route:list --path=admin

Prefer dump() over dd() in loops

dump($user);

dump() doesn’t halt execution, making it safer during iteration.

Queue slow tasks

Emails, exports, and API calls should be queued:

php artisan queue:work

This keeps requests fast and improves user experience.

Respect Laravel environments

Use .env files properly and avoid hardcoding environment logic in your codebase.

Read Laravel error pages carefully

Laravel’s exception pages are detailed for a reason — the stack trace usually points straight to the issue.

Final Thoughts

Mastering Laravel commands — from Artisan to npm run dev and npm run build — dramatically improves development speed and confidence. Once these commands become muscle memory, Laravel really starts to shine.

If you’re serious about Laravel development, keep a personal list of commands and patterns you use most. It pays off fast.

Happy building 🚀

Newsletter

Stay in the loop.

Occasional updates on new posts, Laravel & Livewire tips, and behind-the-scenes from travel, photography and drone projects. No spam, ever.

Unsubscribe anytime with one click.