PHPackages                             jcesarbueno/laravel-strategy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jcesarbueno/laravel-strategy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jcesarbueno/laravel-strategy
============================

A Laravel package for generating Strategy Design Pattern, along with Factory and Chain of Responsibility support.This package provides an Artisan command to quickly scaffold strategies, keeping your Laravel project well-structured.

v1.0.0(1y ago)23MITPHPPHP &gt;=8.0CI passing

Since Mar 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jcesarbueno/laravel-strategy)[ Packagist](https://packagist.org/packages/jcesarbueno/laravel-strategy)[ RSS](/packages/jcesarbueno-laravel-strategy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

[![Latest Version](https://camo.githubusercontent.com/cd76f8b19cda09fa8823e5e7c753f04ee6bb98a7d4938a96220a33e37e663f2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a63657361726275656e6f2f6c61726176656c2d73747261746567792e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/jcesarbueno/laravel-strategy)[![PHP Version](https://camo.githubusercontent.com/fd68fac9bc14aac87d00e3752395297e22779f6fd3aeb5dc7433437f40558f82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a63657361726275656e6f2f6c61726176656c2d73747261746567792e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Tests](https://github.com/jcesarbueno/laravel-strategy/actions/workflows/tests.yml/badge.svg)](https://github.com/jcesarbueno/laravel-strategy/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/a31025cfd38a4b79ef72406183a4901e3c96a41881be65792a7dff0b3713ba89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a63657361726275656e6f2f6c61726176656c2d73747261746567792e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/jcesarbueno/laravel-strategy)

🎯 Laravel Strategy Package
==========================

[](#-laravel-strategy-package)

A Laravel package for generating **Strategy Design Pattern**, along with **Factory** and **Chain of Responsibility** support.
This package provides an **Artisan command** to quickly scaffold strategies, keeping your Laravel project well-structured.

---

🚀 Features
----------

[](#-features)

- ✅ **Generates Strategy Pattern classes**
- ✅ **Creates a Factory** for handling strategy instances
- ✅ **Supports Chain of Responsibility (Pipelines)**
- ✅ **Keeps Strategies organized in a dedicated folder**
- ✅ **Fully tested with PestPHP &amp; PHPStan for static analysis**

---

📦 Installation
--------------

[](#-installation)

Require the package via Composer:

```
composer require jcesarbueno/laravel-strategy:^1.0
```

---

⚙️ How It Works
===============

[](#️-how-it-works)

Run the following Artisan command:

```
php artisan make:strategy SendNotification
```

You will be prompted with interactive questions:

1️⃣ Which methods should it have? (Enter method names one by one, press Enter on an empty line to finish)

2️⃣ Which concrete implementations should it have? (Enter class names one by one, press Enter on an empty line to finish)

3️⃣ Do you want to create Pipelines (Chain of Responsibility) for the Strategy? (Answer yes or no)

📁 Generated Structure
=====================

[](#-generated-structure)

For example, if you create a SendNotification strategy with method send(), and implementations ApiEvent, SlackEvent and EmailEvent, the package will generate:

```
app/Strategies/SendNotification/
│── Contracts/
│   └── SendNotificationContract.php
│── Factories/
│   └── SendNotificationFactory.php
│── Pipelines/
│   └── SendNotificationPipeline.php  (if selected)
│── Implementations/
│   ├── ApiNotification.php
│   ├── SlackNotification.php
│   ├── EmailNotification.php
```

Then, you can use the SendNotificationFactory to get the desired implementation:

```
use App\Strategies\SendNotification\Factories\SendNotificationFactory;
use App\Models\Customer;

$notificationType = Customer::find(1)->notification_type;

// Choose the implementation in runtime
$sendNotification = SendNotificationFactory::make($notificationType);

$sendNotification->send();
```

You can also use the prebuilt Pipeline to handle the chain of responsibility:

You can create more than one pipeline for the same strategy, each one with a different responsibility. Just copy the SendNotificationPipeline and change the name.

```
namespace App\Strategies\SendNotification\Pipelines;

use Closure;

class EnsureNotificationTextIsNotEmpty
{
    public function handle($customer, Closure $next)
    {
        if (empty($customer->event->text)) {
            throw new \Exception('Notification text cannot be empty');
        }

        return $next($customer);
    }
}
```

```
namespace App\Strategies\SendNotification\Pipelines;

use Closure;

class EnsureCustomerHasEmail
{
    public function handle($customer, Closure $next)
    {
        if (empty($customer->email)) {
            throw new \Exception('Customer must have an email');
        }

        return $next($customer);
    }
}
```

Then, you can choose which pipeline to use in each implementation using the function getPipelines():

```
public function getPipelines(): array
{
    return [
        EnsureNotificationTextIsNotEmpty::class,
        EnsureCustomerHasEmail::class,
    ];
}
```

And another implementation can have a different pipeline:

```
public function getPipelines(): array
{
    return [
        EnsureNotificationTextIsNotEmpty::class,
    ];
}
```

Now you just call the Pipeline after creating the strategy:

```
use App\Strategies\SendNotification\Factories\SendNotificationFactory;
use App\Models\Customer;
use Illuminate\Support\Facades\Pipeline;

$customer = Customer::find(1);

$sendNotification = SendNotificationFactory::make($customer->notification_type);

Pipeline::send($customer)
    ->through($sendNotification->getPipelines())
    ->then(function ($customer) use ($sendNotification) {
        $sendNotification->send();
    });
```

Other Usages for Pipelines
--------------------------

[](#other-usages-for-pipelines)

You can use the Pipeline to filter the data before sending it to the strategy, or to handle exceptions in a more organized way.

```
namespace App\Strategies\SendNotification\Pipelines;

use Illuminate\Support\Collection;
use Closure;

class FilterNotSendedEvents
{
    public function handle(Collection $events, Closure $next)
    {
       $events->filter(function ($event) {
            return $event->sended === false;
        });

        return $next($events);
    }
}
```

Just chain the Pipelines to filter the desired data.

```
use App\Strategies\SendNotification\Factories\SendNotificationFactory;
use App\Models\Customer;
use Illuminate\Support\Facades\Pipeline;

$customer = Customer::with('events')->find(1);

$sendNotification = SendNotificationFactory::make($customer->notification_type);

$filteredEvents = Pipeline::send($customer->events)
    ->through($sendNotification->getPipelines())
    ->thenReturn();

$sendNotification->send($filteredEvents);
```

---

📝 License
---------

[](#-license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

---

🧑‍💻 Author
----------

[](#‍-author)

This package was created by Júlio César Bueno, Laravel developer since 2023.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance44

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

436d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/444d20f62e37e0cb8e3d661600987e4784f5d825f5ca72bf318fb45d9bc720e4?d=identicon)[jcesarbueno](/maintainers/jcesarbueno)

---

Tags

laraveldesignpatternstrategy

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jcesarbueno-laravel-strategy/health.svg)

```
[![Health](https://phpackages.com/badges/jcesarbueno-laravel-strategy/health.svg)](https://phpackages.com/packages/jcesarbueno-laravel-strategy)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81161.3k](/packages/getsolaris-laravel-make-service)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
