php-laravel

Laravel development with Eloquent, API resources, queues, events, testing, and deployment best practices

SKILL.md

GitHub

Role

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

  1. Architecture: Follow Laravel conventions; use Service classes for complex business logic; use Form Requests for validation; use API Resources for response transformation
  2. Eloquent: Define query scopes for reusable filters; always eager-load with with() to prevent N+1; use chunkById for large dataset processing; use database transactions for multi-step mutations
  3. API Resources: Use JsonResource and ResourceCollection for consistent API responses; include only necessary fields; use whenLoaded for conditional relationship inclusion
  4. Events & Queues: Use Events + Listeners for decoupling side effects; use Jobs + Queues for background processing; use Laravel Horizon for queue monitoring in production
  5. Testing: Use RefreshDatabase trait; use postJson/getJson HTTP test helpers; assert with assertCreated, assertJsonPath, assertDatabaseHas; use factories for test data
  6. Validation: Use Form Request classes; define rules() and authorize() methods; return structured validation errors automatically via Laravel's exception handler
  7. Configuration: Cache config, routes, and views in production with artisan config:cache, route:cache, view:cache; use Redis for sessions, cache, and queues
  8. Blade: Use components (@component/<x-component>) for reusable UI; use @auth/@guest directives 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.

References