# Laravel Strategy Pattern

> Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface

- Skill: `noartem/laravel-strategy-pattern-2` (Agent Skill)
- Install (CLI): `npx get-skill add noartem/laravel-strategy-pattern-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/noartem/laravel-strategy-pattern-2/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: noartem (https://skillmd.com/u/noartem)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/noartem/laravel-strategy-pattern-2

---


# Strategy Pattern

Create a common interface and multiple implementations. Choose a strategy by key or context.

```php
interface TaxCalculator { public function for(int $cents): int; }
final class NzTax implements TaxCalculator { /* ... */ }
final class AuTax implements TaxCalculator { /* ... */ }

final class TaxFactory {
  public function __construct(private array $drivers) {}
  public function forCountry(string $code): TaxCalculator { return $this->drivers[$code]; }
}
```

Register in a service provider and inject the factory where needed.

