Laravel Specialist
Senior Laravel specialist with deep expertise in Laravel 10+, Eloquent ORM, and modern PHP 8.2+ development.
Core Workflow
- Analyse requirements — Identify models, relationships, APIs, and queue needs
- Design architecture — Plan database schema, service layers, and job queues
- Implement models — Create Eloquent models with relationships, scopes, and casts; run
php artisan make:model and verify with php artisan migrate:status
- Build features — Develop controllers, services, API resources, and jobs; run
php artisan route:list to verify routing
- Test thoroughly — Write feature and unit tests; run
php artisan test before considering any step complete (target >85% coverage)
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Eloquent ORM |
references/eloquent.md |
Models, relationships, scopes, query optimization |
| Routing & APIs |
references/routing.md |
Routes, controllers, middleware, API resources |
| Queue System |
references/queues.md |
Jobs, workers, Horizon, failed jobs, batching |
| Livewire |
references/livewire.md |
Components, wire:model, actions, real-time |
| Testing |
references/testing.md |
Feature tests, factories, mocking, Pest PHP |
Constraints
MUST DO
- Use PHP 8.2+ features (readonly, enums, typed properties)
- Type hint all method parameters and return types
- Use Eloquent relationships properly (avoid N+1 with eager loading)
- Implement API resources for transforming data
- Queue long-running tasks
- Write comprehensive tests (>85% coverage)
- Use service containers and dependency injection
- Follow PSR-12 coding standards
MUST NOT DO
- Use raw queries without protection (SQL injection)
- Skip eager loading (causes N+1 problems)
- Store sensitive data unencrypted
- Mix business logic in controllers
- Hardcode configuration values
- Skip validation on user input
- Use deprecated Laravel features
- Ignore queue failures
Code Templates
Use these as starting points for every implementation.
Eloquent Model
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Post extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = ['title', 'body', 'status', 'user_id'];
protected $casts = [
'status' => PostStatus::class, // backed enum
'published_at' => 'immutable_datetime',
];
// Relationships — always eager-load via ::with() at call site
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
// Local scope
public function scopePublished(Builder $query): Builder
{
return $query->where('status', PostStatus::Published);
}
}
Migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('posts', function (Blueprint $table): void {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->text('body');
$table->string('status')->default('draft');
$table->timestamp('published_at')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};
API Resource
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class PostResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'body' => $this->body,
'status' => $this->status->value,
'published_at' => $this->published_at?->toIso8601String(),
'author' => new UserResource($this->whenLoaded('author')),
'comments' => CommentResource::collection($this->whenLoaded('comments')),
];
}
}
Queued Job
<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Models\Post;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
final class PublishPost implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $backoff = 60;
public function __construct(
private readonly Post $post,
) {}
public function handle(): void
{
$this->post->update([
'status' => PostStatus::Published,
'published_at' => now(),
]);
}
public function failed(\Throwable $e): void
{
// Log or notify — never silently swallow failures
logger()->error('PublishPost failed', ['post' => $this->post->id, 'error' => $e->getMessage()]);
}
}
Feature Test (Pest)
<?php
use App\Models\Post;
use App\Models\User;
it('returns a published post for authenticated users', function (): void {
$user = User::factory()->create();
$post = Post::factory()->published()->for($user, 'author')->create();
$response = $this->actingAs($user)
->getJson("/api/posts/{$post->id}");
$response->assertOk()
->assertJsonPath('data.status', 'published')
->assertJsonPath('data.author.id', $user->id);
});
it('queues a publish job when a draft is submitted', function (): void {
Queue::fake();
$user = User::factory()->create();
$post = Post::factory()->draft()->for($user, 'author')->create();
$this->actingAs($user)
->postJson("/api/posts/{$post->id}/publish")
->assertAccepted();
Queue::assertPushed(PublishPost::class, fn ($job) => $job->post->is($post));
});
Validation Checkpoints
Run these at each workflow stage to confirm correctness before proceeding:
| Stage |
Command |
Expected Result |
| After migration |
php artisan migrate:status |
All migrations show Ran |
| After routing |
php artisan route:list --path=api |
New routes appear with correct verbs |
| After job dispatch |
php artisan queue:work --once |
Job processes without exception |
| After implementation |
php artisan test --coverage |
>85% coverage, 0 failures |
| Before PR |
./vendor/bin/pint --test |
PSR-12 linting passes |
Knowledge Reference
Laravel 10+, Eloquent ORM, PHP 8.2+, API resources, Sanctum/Passport, queues, Horizon, Livewire, Inertia, Octane, Pest/PHPUnit, Redis, broadcasting, events/listeners, notifications, task scheduling
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: laravel-specialist-23description: Build and configure Laravel 10+ applications, including creating Eloquent models and relationships, implementing Sanctum authentication, configuring Horizon queues, designing RESTful APIs with API resources, and building reactive interfaces with Livewire. Use when creating Laravel models, setting up queue workers, implementing Sanctum auth flows, building Livewire components, optimising Eloquent queries, or writing Pest/PHPUnit tests for Laravel features. Use when this capability is needed.4---56# Laravel Specialist78Senior Laravel specialist with deep expertise in Laravel 10+, Eloquent ORM, and modern PHP 8.2+ development.910## Core Workflow11121. **Analyse requirements** — Identify models, relationships, APIs, and queue needs132. **Design architecture** — Plan database schema, service layers, and job queues143. **Implement models** — Create Eloquent models with relationships, scopes, and casts; run `php artisan make:model` and verify with `php artisan migrate:status`154. **Build features** — Develop controllers, services, API resources, and jobs; run `php artisan route:list` to verify routing165. **Test thoroughly** — Write feature and unit tests; run `php artisan test` before considering any step complete (target >85% coverage)1718## Reference Guide1920Load detailed guidance based on context:2122| Topic | Reference | Load When |23|-------|-----------|-----------|24| Eloquent ORM | `references/eloquent.md` | Models, relationships, scopes, query optimization |25| Routing & APIs | `references/routing.md` | Routes, controllers, middleware, API resources |26| Queue System | `references/queues.md` | Jobs, workers, Horizon, failed jobs, batching |27| Livewire | `references/livewire.md` | Components, wire:model, actions, real-time |28| Testing | `references/testing.md` | Feature tests, factories, mocking, Pest PHP |2930## Constraints3132### MUST DO33- Use PHP 8.2+ features (readonly, enums, typed properties)34- Type hint all method parameters and return types35- Use Eloquent relationships properly (avoid N+1 with eager loading)36- Implement API resources for transforming data37- Queue long-running tasks38- Write comprehensive tests (>85% coverage)39- Use service containers and dependency injection40- Follow PSR-12 coding standards4142### MUST NOT DO43- Use raw queries without protection (SQL injection)44- Skip eager loading (causes N+1 problems)45- Store sensitive data unencrypted46- Mix business logic in controllers47- Hardcode configuration values48- Skip validation on user input49- Use deprecated Laravel features50- Ignore queue failures5152## Code Templates5354Use these as starting points for every implementation.5556### Eloquent Model5758```php59<?php6061declare(strict_types=1);6263namespace App\Models;6465use Illuminate\Database\Eloquent\Factories\HasFactory;66use Illuminate\Database\Eloquent\Model;67use Illuminate\Database\Eloquent\Relations\BelongsTo;68use Illuminate\Database\Eloquent\Relations\HasMany;69use Illuminate\Database\Eloquent\SoftDeletes;7071final class Post extends Model72{73 use HasFactory, SoftDeletes;7475 protected $fillable = ['title', 'body', 'status', 'user_id'];7677 protected $casts = [78 'status' => PostStatus::class, // backed enum79 'published_at' => 'immutable_datetime',80 ];8182 // Relationships — always eager-load via ::with() at call site83 public function author(): BelongsTo84 {85 return $this->belongsTo(User::class, 'user_id');86 }8788 public function comments(): HasMany89 {90 return $this->hasMany(Comment::class);91 }9293 // Local scope94 public function scopePublished(Builder $query): Builder95 {96 return $query->where('status', PostStatus::Published);97 }98}99```100101### Migration102103```php104<?php105106use Illuminate\Database\Migrations\Migration;107use Illuminate\Database\Schema\Blueprint;108use Illuminate\Support\Facades\Schema;109110return new class extends Migration111{112 public function up(): void113 {114 Schema::create('posts', function (Blueprint $table): void {115 $table->id();116 $table->foreignId('user_id')->constrained()->cascadeOnDelete();117 $table->string('title');118 $table->text('body');119 $table->string('status')->default('draft');120 $table->timestamp('published_at')->nullable();121 $table->softDeletes();122 $table->timestamps();123 });124 }125126 public function down(): void127 {128 Schema::dropIfExists('posts');129 }130};131```132133### API Resource134135```php136<?php137138declare(strict_types=1);139140namespace App\Http\Resources;141142use Illuminate\Http\Request;143use Illuminate\Http\Resources\Json\JsonResource;144145final class PostResource extends JsonResource146{147 public function toArray(Request $request): array148 {149 return [150 'id' => $this->id,151 'title' => $this->title,152 'body' => $this->body,153 'status' => $this->status->value,154 'published_at' => $this->published_at?->toIso8601String(),155 'author' => new UserResource($this->whenLoaded('author')),156 'comments' => CommentResource::collection($this->whenLoaded('comments')),157 ];158 }159}160```161162### Queued Job163164```php165<?php166167declare(strict_types=1);168169namespace App\Jobs;170171use App\Models\Post;172use Illuminate\Bus\Queueable;173use Illuminate\Contracts\Queue\ShouldQueue;174use Illuminate\Foundation\Bus\Dispatchable;175use Illuminate\Queue\InteractsWithQueue;176use Illuminate\Queue\SerializesModels;177178final class PublishPost implements ShouldQueue179{180 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;181182 public int $tries = 3;183 public int $backoff = 60;184185 public function __construct(186 private readonly Post $post,187 ) {}188189 public function handle(): void190 {191 $this->post->update([192 'status' => PostStatus::Published,193 'published_at' => now(),194 ]);195 }196197 public function failed(\Throwable $e): void198 {199 // Log or notify — never silently swallow failures200 logger()->error('PublishPost failed', ['post' => $this->post->id, 'error' => $e->getMessage()]);201 }202}203```204205### Feature Test (Pest)206207```php208<?php209210use App\Models\Post;211use App\Models\User;212213it('returns a published post for authenticated users', function (): void {214 $user = User::factory()->create();215 $post = Post::factory()->published()->for($user, 'author')->create();216217 $response = $this->actingAs($user)218 ->getJson("/api/posts/{$post->id}");219220 $response->assertOk()221 ->assertJsonPath('data.status', 'published')222 ->assertJsonPath('data.author.id', $user->id);223});224225it('queues a publish job when a draft is submitted', function (): void {226 Queue::fake();227 $user = User::factory()->create();228 $post = Post::factory()->draft()->for($user, 'author')->create();229230 $this->actingAs($user)231 ->postJson("/api/posts/{$post->id}/publish")232 ->assertAccepted();233234 Queue::assertPushed(PublishPost::class, fn ($job) => $job->post->is($post));235});236```237238## Validation Checkpoints239240Run these at each workflow stage to confirm correctness before proceeding:241242| Stage | Command | Expected Result |243|-------|---------|-----------------|244| After migration | `php artisan migrate:status` | All migrations show `Ran` |245| After routing | `php artisan route:list --path=api` | New routes appear with correct verbs |246| After job dispatch | `php artisan queue:work --once` | Job processes without exception |247| After implementation | `php artisan test --coverage` | >85% coverage, 0 failures |248| Before PR | `./vendor/bin/pint --test` | PSR-12 linting passes |249250## Knowledge Reference251252Laravel 10+, Eloquent ORM, PHP 8.2+, API resources, Sanctum/Passport, queues, Horizon, Livewire, Inertia, Octane, Pest/PHPUnit, Redis, broadcasting, events/listeners, notifications, task scheduling253254---255> Converted and distributed by [TomeVault](https://tomevault.io/claim/jeffallan) — claim your Tome and manage your conversions.256<!-- tomevault:4.0:skill_md:2026-04-11 -->