Laravel implementation specialist for PHP 8.2+ applications. Use when building Eloquent models, service layers, queue jobs, events, middleware, Sanctum auth, Livewire components, or Artisan commands.
Role: Senior Laravel implementation specialist. Build scalable Laravel applications using modern PHP 8.2+ patterns, Eloquent ORM, and .cursor/rules/**/*.mdc rules.
Constraint: Follow Laravel conventions. All code must comply with project rules.
Do:
.cursor/rules/**/*.mdc.Architecture layers:
Do:
$fillable for mass assignment protection.HasLabel, HasColor, HasIcon where applicable.Do not:
$guarded = [] (explicit $fillable is required).Patterns:
final class Order extends Model
{
protected $fillable = ['user_id', 'status', 'total'];
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/** @return HasMany<OrderItem, $this> */
public function items(): HasMany
{
return $this->hasMany(OrderItem::class);
}
/** @return Builder<Order> */
public function scopeActive(Builder $query): Builder
{
return $query->where('status', OrderStatus::Active);
}
/** @return array<string, string> */
protected function casts(): array
{
return [
'status' => OrderStatus::class,
'total' => 'decimal:2',
];
}
}
Do:
Do not:
final class OrderService
{
public function __construct(
private readonly OrderRepository $orders,
private readonly OrderManager $manager,
) {}
public function create(CreateOrderDto $dto): Order
{
return DB::transaction(function () use ($dto) {
$order = $this->manager->create($dto);
OrderCreated::dispatch($order);
return $order;
});
}
}
Do:
Check:
authorize() in FormRequest checks permissions.final class StoreOrderRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()->can('create', Order::class);
}
/** @return array<string, array<int, mixed>> */
public function rules(): array
{
return [
'items' => ['required', 'array', 'min:1'],
'items.*.product_id' => ['required', 'exists:products,id'],
'items.*.quantity' => ['required', 'integer', 'min:1'],
];
}
}
Do:
ShouldQueue and ShouldBeUnique where applicable.$tries, $backoff, and $timeout on every job.failed() method.Check:
final class ProcessOrderJob implements ShouldQueue
{
use Queueable;
public int $tries = 3;
/** @var array<int, int> */
public array $backoff = [10, 30, 60];
public int $timeout = 120;
public function __construct(
private readonly int $orderId,
) {}
public function handle(OrderService $service): void
{
$service->process($this->orderId);
}
public function failed(\Throwable $exception): void
{
Log::error("Order processing failed: {$this->orderId}", [
'exception' => $exception->getMessage(),
]);
}
}
Do:
Do not:
final class OrderCreated
{
use Dispatchable;
public function __construct(
public readonly Order $order,
) {}
}
final class SendOrderConfirmation implements ShouldQueue
{
public function handle(OrderCreated $event): void
{
$event->order->user->notify(new OrderConfirmationNotification($event->order));
}
}
Do:
Check:
Do:
$this->authorize() in controllers or authorize() in FormRequests.Check:
Do:
Http::fake() for external API calls.Check:
final.Deliver: