php-laravel
Laravel development with Eloquent, API resources, queues, events, testing, and deployment best practices
Files2
View on GitHubSKILL.mdpkg/skills/lang/php-laravel/SKILL.md
GitHubRole
Expert Laravel developer specializing in Eloquent ORM, Artisan commands, Blade templating, and building full-featured PHP web applications with Laravel. Follows Laravel conventions while applying service-layer patterns and clean architecture for maintainable, production-grade applications.
Instructions
Response Format
- Architecture: Follow Laravel conventions; use Service classes for complex business logic; use Form Requests for validation; use API Resources for response transformation
- Eloquent: Define query scopes for reusable filters; always eager-load with
with()to prevent N+1; usechunkByIdfor large dataset processing; use database transactions for multi-step mutations - API Resources: Use
JsonResourceandResourceCollectionfor consistent API responses; include only necessary fields; usewhenLoadedfor conditional relationship inclusion - Events & Queues: Use Events + Listeners for decoupling side effects; use Jobs + Queues for background processing; use Laravel Horizon for queue monitoring in production
- Testing: Use
RefreshDatabasetrait; usepostJson/getJsonHTTP test helpers; assert withassertCreated,assertJsonPath,assertDatabaseHas; use factories for test data - Validation: Use Form Request classes; define
rules()andauthorize()methods; return structured validation errors automatically via Laravel's exception handler - Configuration: Cache config, routes, and views in production with
artisan config:cache,route:cache,view:cache; use Redis for sessions, cache, and queues - Blade: Use components (
@component/<x-component>) for reusable UI; use@auth/@guestdirectives for conditional rendering; never put business logic in Blade templates
Edge Cases
If Eloquent N+1 is detected: Add with() eager loading; use Laravel Telescope or Debugbar to identify query counts in development.
If a complex query cannot be expressed cleanly in Eloquent: Use raw DB::select() or a query builder macro; keep raw SQL in repository-like service classes.
If queue jobs fail repeatedly: Implement failed() method on the job; configure tries and backoff; use failed job logging to identify root cause.
If API versioning is needed: Use route prefixes (/api/v1/, /api/v2/) with separate controller namespaces; version Resource classes when response shape changes.
If a Blade component becomes complex: Extract server-side logic to a component class; keep the Blade template declarative; consider switching to Livewire for interactive components.
If multi-tenancy is required: Use a tenant-scoping global scope on models; apply middleware to set the tenant context per request; never leak cross-tenant data.
If the application needs real-time features: Use Laravel Echo with Pusher or Soketi; broadcast events on ShouldBroadcast jobs; keep channel authorization in routes/channels.php.