Essential Artisan Commands
# Project setup
php artisan key:generate # Generate app key
php artisan migrate # Run migrations
php artisan db:seed # Seed database
# Make resources
php artisan make:model User -mfsc # Model, migration, factory, seeder, controller
php artisan make:controller APIController --api
php artisan make:request StoreUserRequest
php artisan make:middleware CheckToken
php artisan make:job SendEmail
php artisan make:test FeatureTest
php artisan make:rule ValidDomain
# Run code
php artisan tinker # Interactive shell
php artisan test # Run tests
php artisan queue:work # Process jobs
# Debugging
php artisan optimize # Cache config/routes/providers
php artisan route:list # Show all routes
php artisan config:show app # Show specific config
Common HTTP Status Codes
| Code | Meaning | When to Use | |------|---------|------------| | 200 | OK | Request successful | | 201 | Created | Resource created | | 204 | No Content | Successful deletion | | 400 | Bad Request | Invalid request format | | 401 | Unauthorized | Authentication required/failed | | 403 | Forbidden | Authorized but access denied | | 404 | Not Found | Resource doesn't exist | | 422 | Unprocessable Entity | Validation failed | | 429 | Too Many Requests | Rate limited | | 500 | Server Error | Something went wrong | | 503 | Unavailable | Service temporarily down |
Useful Facades
Auth::user() # Get current user
Cache::remember('key', 3600, fn()) # Cache with fallback
DB::select('SELECT *') # Raw query
Event::dispatch(new OrderShipped()) # Dispatch event
File::get('path/to/file') # Read file
Log::info('message', ['context']) # Log message
Mail::send(new OrderMailed()) # Send email
Queue::dispatch(new Job()) # Queue job
Route::get('/path', Action::class) # Define route
Storage::put('path', 'content') # Store file
Validator::make($data, $rules) # Validate data
Testing Helpers
$this->getJson('/api/endpoint') # HTTP GET
$this->postJson('/api/endpoint', $data)
$this->putJson('/api/endpoint', $data)
$this->deleteJson('/api/endpoint')
$response->assertStatus(200) # Check status
$response->assertJsonPath('key', value)
$response->assertJsonStructure([...])
$response->assertJson([...])
Appendix B: Troubleshooting Guide
Common Issues & Solutions
Q: Tests are slow
A: Run tests in parallel: php artisan test --parallel
Q: Queue jobs not processing
A: Check queue worker is running: php artisan queue:work
Next, check for failed jobs: php artisan queue:failed
Q: 404 errors for valid routes
A: Clear route cache: php artisan route:clear
Regenerate cache: php artisan route:cache
Q: Database connection errors
A: Check .env database credentials
Test connection: php artisan tinker → DB::connection()->getPdo()
Q: Authentication not working
A: Verify middleware is in route group
Check token is being sent correctly
Verify token exists in database: Bearer::where('token', $token)->first()
Q: Memory issues during long operations A: Use chunking for large queries:
Model::chunk(1000, function ($records) {
// Process $records
});
Q: N+1 queries killing performance
A: Use eager loading: Model::with(['relation'])->get()
Debug with: DB::enableQueryLog() → dd(DB::getQueryLog())
Q: CORS errors in browser
A: Check CORS middleware is registered in bootstrap/app.php
Verify CORS_ALLOWED_ORIGINS in .env
Add exposed headers if using rate limiting
Q: Rate limiting not working
A: Check Redis/cache is configured correctly
Test cache: Cache::put('test', true) → Cache::get('test')
Q: Validation messages in wrong language
A: Check APP_LOCALE in .env
Verify translation files exist in lang/[locale]/
Test with: __('validation.email_required')
Conclusion
Building fast, reliable APIs is a journey. You now have the foundational knowledge to:
- Design scalable architecture using proven patterns
- Implement security from day one with authentication and authorization
- Handle errors gracefully with centralized exception handling
- Optimize for performance with caching and compression
- Test thoroughly with comprehensive test suites
- Monitor effectively with logging and observability
- Ship confidently with CI/CD pipelines
Key Takeaways
- Convention over Configuration: Let Laravel's defaults guide you
- Type Safety: Use PHP 8.4 types to catch bugs early
- Test Everything: Automated tests are your safety net
- Monitor in Production: You can't fix what you can't see
- Plan for Evolution: Design APIs that grow gracefully
- Document Well: Clear documentation reduces support burden
- Secure by Default: Security is everyone's responsibility
Next Steps
- Start with a small project and apply these patterns
- Read the Laravel documentation for deeper understanding
- Study successful open-source APIs
- Deploy to production and iterate
- Join the Laravel community and share knowledge
Happy shipping! 🚀
Additional Resources
Official Documentation
Community Resources
- Laravel News (news.laravel.com)
- Laracasts (laracasts.com) - Video tutorials
- Laravel Forum (laracasts.com/discuss)
- Stack Overflow (tag: laravel)
Tools & Services
- Laravel Forge - Server deployment
- Laravel Vapor - Serverless deployment
- Sentry - Error tracking
- Datadog - Monitoring
A practical guide to shipping production REST APIs without getting bogged down in unnecessary complexity
This book evolves with the Webplo License API, documenting real patterns and decisions made in production.
This book is based on Laravel Shipping Fast principles. Version: 1.0 | Updated: 2026