Artisan Commands
Artisan is Laravel's CLI tool. Below are the most commonly used commands for the CPR backend.
Development
| Command | Description |
|---|---|
php artisan serve | Start the development server |
php artisan tinker | Interactive REPL for testing code |
php artisan route:list | List all registered routes |
php artisan route:list --path=api/v1 | List API v1 routes only |
Database
| Command | Description |
|---|---|
php artisan migrate | Run pending migrations |
php artisan migrate:fresh --seed | Drop all tables, re-migrate, and seed |
php artisan migrate:rollback | Rollback last migration batch |
php artisan migrate:status | Check migration status |
php artisan db:seed | Run all seeders |
php artisan db:seed --class=RoleSeeder | Run a specific seeder |
Code Generation
| Command | Description |
|---|---|
php artisan make:model ModelName -m | Create model with migration |
php artisan make:controller Api/V1/ExampleController | Create API controller |
php artisan make:request StoreExampleRequest | Create Form Request |
php artisan make:resource ExampleResource | Create API Resource |
php artisan make:factory ExampleFactory | Create model factory |
php artisan make:seeder ExampleSeeder | Create seeder |
php artisan make:migration create_examples_table | Create migration |
php artisan make:test Feature/Api/V1/ExampleTest | Create test file |
Cache & Optimization
| Command | Description |
|---|---|
php artisan config:cache | Cache configuration (production) |
php artisan config:clear | Clear config cache (development) |
php artisan route:cache | Cache routes (production) |
php artisan route:clear | Clear route cache |
php artisan view:cache | Cache Blade views |
php artisan view:clear | Clear view cache |
php artisan optimize | Run all optimization commands |
php artisan optimize:clear | Clear all caches |
Queue
| Command | Description |
|---|---|
php artisan queue:work | Start processing queued jobs |
php artisan queue:listen | Listen for jobs (restarts on code change) |
php artisan queue:retry all | Retry all failed jobs |
php artisan queue:flush | Flush all failed jobs |
Logging & Debugging
| Command | Description |
|---|---|
php artisan pail | Real-time log tailing |
php artisan pail --filter="error" | Filter logs by level |
Testing
| Command | Description |
|---|---|
php artisan test | Run all tests |
php artisan test --parallel --processes=10 | Run tests in parallel |
php artisan test --filter=PatientTest | Run specific test |
Useful Tips
List All Available Commands
bash
php artisan listGet Help for a Command
bash
php artisan help migrateUsing with Sail (Docker)
When using Docker via Laravel Sail, prefix all commands:
bash
./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan db:seed
./vendor/bin/sail artisan test