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...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Laravel Strategy Pattern?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/comeonoliver-laravel-strategy-pattern)
# 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.