About laravel-strategy-pattern
A Laravel skill for structuring interchangeable strategies behind a shared interface. It shows how to select implementations by key or context and register a factory through a service provider.
Key features
- 01Shared strategy interface
- 02Multiple interchangeable implementations
- 03Factory selection by country code
- 04Service provider registration
Use cases
- 01Choosing tax calculation rules by country
- 02Injecting a strategy factory into application services
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ noartem/ skills --skill laravel-strategy-patternAfter installing, type/laravel-strategy-patternin Claude Code to confirm it loaded.
Details
From the project READMEStrategy Pattern
Create a common interface and multiple implementations. Choose a strategy by key or context.
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.
Comments
Markdown supported