php artisan is Laravel’s command-line interface. It helps you generate code, manage the app lifecycle, work with the database, debug, and maintain the project efficiently.
1. Controller Commands
1.1 Basic Controller
php artisan make:controller UserController
What it does
- Creates an empty controller class in
app/Http/Controllers
Use case
- When you want full control and plan to manually define methods.
Example
class UserController extends Controller {
public function index() {}
public function store() {}
}
1.2 Resource Controller
php artisan make:controller UserController --resource
What it generates
- A controller with CRUD methods
Methods included:
index()create()store()show()edit()update()destroy()
Use case
- Best for MVC web apps
- Works perfectly with:
Route::resource('users', UserController::class);
1.3 API Resource Controller
php artisan make:controller UserController --api
Difference from --resource
-
Removes UI-related methods:
- ❌
create() - ❌
edit()
- ❌
Use case
- REST APIs (JSON only)
- Common in Sanctum / JWT based APIs
1.4 Invokable Controller
php artisan make:controller UserController --invokable
What it creates
- A controller with only
__invoke()
Use case
- Single-responsibility routes
- Clean and readable for small actions
Example
Route::post('/login', LoginController::class);
2. View & UI Related Commands
2.1 Create a Blade View
php artisan make:view about
Creates
resources/views/about.blade.php
Use case
- Quickly scaffold views for pages
2.2 Blade Component
php artisan make:component About
Creates
- Component class
- Blade view
Use case
- Reusable UI elements
- Headers, buttons, modals
Example
<x-about />
3. Model & Database Layer
3.1 Create Model
php artisan make:model Course
Creates
app/Models/Course.php
Common variants
php artisan make:model Course -m # with migration
php artisan make:model Course -f # with factory
php artisan make:model Course -s # with seeder
php artisan make:model Course -a # all
3.2 Show Model Info (Laravel 10+)
php artisan model:show Course
Displays
- Table name
- Columns
- Relationships
- Casts
Use case
- Debugging models
- Understanding schema quickly
4. Migration Commands
4.1 Create Migration
php artisan make:migration create_posts_table
Creates
database/migrations/xxxx_create_posts_table.php
4.2 Run Migrations
php artisan migrate
Use case
- Apply schema changes
4.3 Rollback Migrations
php artisan migrate:rollback --step=3
Use case
- Undo last 3 migrations
4.4 Reset All Migrations
php artisan migrate:reset
Danger
- Drops all tables
4.5 Refresh Migrations
php artisan migrate:refresh
Does
- Rollback + re-run migrations
Useful during development.
4.6 Run a Specific Migration
php artisan migrate --path=/database/migrations/2026_01_04_150744_create_teachers_table.php
Use case
- Fixing or testing one migration
5. Seeder & Database Data
5.1 Create Seeder
php artisan make:seeder TeachersSeeder
5.2 Run Seeder
php artisan db:seed --class=TeachersSeeder
Use case
- Insert test or default data
6. Validation, Middleware, Security
6.1 Custom Validation Rule
php artisan make:rule Uppercase
Use case
- Reusable complex validation logic
6.2 Middleware
php artisan make:middleware CheckRole
Use case
- Authentication
- Authorization
- Request filtering
7. Authentication & API
7.1 Install API Authentication
php artisan install:api
Installs
- Laravel Sanctum
- API auth scaffolding
7.2 Auth Service Provider
php artisan make:provider AuthServiceProvider
Use case
- Define Gates & Policies
- Authorization logic
8. Mail & Communication
8.1 Create Mail Class
php artisan make:mail WelcomeMail
Use case
- Emails
- Notifications
9. Application Setup & Maintenance
9.1 Generate App Key
php artisan key:generate
Must run
- After cloning a project
- Required for encryption, sessions, cookies
9.2 Storage Symlink
php artisan storage:link
Purpose
- Makes
storage/app/publicaccessible from browser
Use case
- File uploads
- Images
9.3 Maintenance Mode
php artisan down
php artisan down --secret="token"
php artisan up
Use case
- Deployment
- Server maintenance
10. Routing & Debugging
10.1 List Routes
php artisan route:list
php artisan route:list --except-vendor
Use case
- Debug route conflicts
- Check middleware, methods
11. Localization & Stubs
11.1 Enable Localization
php artisan lang:publish
Creates
lang/en/
Use case
- Multi-language apps
11.2 Publish Stubs
php artisan stub:publish
What is a stub?
- Template used by
make:commands
Use case
- Customize default controllers, models, migrations
12. Cache & Optimization
php artisan optimize
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:clear
Use case
- Production performance
- Fix weird cache bugs
13. Queue & Jobs
php artisan make:job SendEmailJob
php artisan queue:work
14. Policy
php artisan make:policy CoursePolicy --model=Course
15. Tinker (Very Important)
php artisan tinker
Use case
- Run Laravel code interactively
- Debug models, queries, services
Top comments (0)