PHPackages                             waqassiwag/laravel-variant-generator - 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. waqassiwag/laravel-variant-generator

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

waqassiwag/laravel-variant-generator
====================================

A Laravel package to generate all possible product variants (Cartesian Product) from a set of attributes.

v1.0.0(yesterday)21↑2900%MITPHPPHP ^8.1

Since Jun 13Pushed yesterdayCompare

[ Source](https://github.com/mohammadwaqas908/laravel-variant-generator)[ Packagist](https://packagist.org/packages/waqassiwag/laravel-variant-generator)[ RSS](/packages/waqassiwag-laravel-variant-generator/feed)WikiDiscussions main Synced today

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

Laravel Variant Generator
=========================

[](#laravel-variant-generator)

A fast and fluent Laravel package to generate all possible product variants (Cartesian Product) from a set of attributes.

[![Run Tests](https://github.com/mohammadwaqas908/laravel-variant-generator/actions/workflows/tests.yml/badge.svg)](https://github.com/mohammadwaqas908/laravel-variant-generator/actions/workflows/tests.yml)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.0+ / 11.0+ / 12.0+

Installation
------------

[](#installation)

```
composer require waqassiwag/laravel-variant-generator
```

Basic Usage
-----------

[](#basic-usage)

Pass an array of your product attributes to generate all possible combinations.

```
use Waqassiwag\VariantGenerator\Facades\VariantGenerator;

$attributes = [
    'Color' => ['Red', 'Blue'],
    'Size' => ['S', 'M'],
    'Material' => ['Cotton', 'Polyester']
];

$variants = VariantGenerator::make($attributes)->generate();
```

**Output:**

```
[
    ['Color' => 'Red', 'Size' => 'S', 'Material' => 'Cotton'],
    ['Color' => 'Red', 'Size' => 'S', 'Material' => 'Polyester'],
    ['Color' => 'Red', 'Size' => 'M', 'Material' => 'Cotton'],
    // ...
]
```

Advanced Features
-----------------

[](#advanced-features)

### 1. Excluding Variants

[](#1-excluding-variants)

Remove specific combinations that you don't want to generate.

```
VariantGenerator::make($attributes)
    ->exclude([
        ['Color' => 'Red', 'Size' => 'S']
    ])
    ->generate();
```

### 2. Custom Formatting

[](#2-custom-formatting)

Modify the output exactly how you need it.

```
VariantGenerator::make($attributes)
    ->format(function ($variant) {
        return implode('-', $variant);
    })
    ->generate();

// Output: ['Red-S-Cotton', 'Red-S-Polyester', ...]
```

### 3. Generating SKUs

[](#3-generating-skus)

Automatically append a unique SKU to each variant.

```
VariantGenerator::make($attributes)
    ->sku(function ($variant) {
        return strtoupper(
            substr($variant['Color'], 0, 3) . substr($variant['Size'], 0, 1)
        );
    })
    ->generate();
```

**Output:**

```
[
    [
        'attributes' => ['Color' => 'Red', 'Size' => 'Small'],
        'sku' => 'REDS'
    ],
    // ...
]
```

### 4. Fluent API

[](#4-fluent-api)

You can chain all these methods together to build complex generation logic cleanly.

```
VariantGenerator::make($attributes)
    ->exclude([['Color' => 'Red', 'Size' => 'S']])
    ->sku(fn ($variant) => strtoupper(substr($variant['Color'],0,3).substr($variant['Size'],0,1)))
    ->format(fn ($variant, $processed) => $processed['sku'] . '-' . $variant['Material'])
    ->generate();
```

> **Tip:** You can also call `->generateAsCollection()` at the end if you prefer working with a Laravel Collection instead of an array.

Testing
-------

[](#testing)

```
composer test
```

Support &amp; Security
----------------------

[](#support--security)

### Support

[](#support)

- **Issues:** [Open an issue in GitHub](https://github.com/mohammadwaqas908/laravel-variant-generator/issues)
- **Security:** If you discover any issues, please email `m.waqas7375@gmail.com`.

Credits
-------

[](#credits)

- [Muhammad Waqas](https://github.com/mohammadwaqas908)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance100

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community2

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

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66936406?v=4)[Mohammad Waqas](/maintainers/mohammadwaqas908)[@mohammadwaqas908](https://github.com/mohammadwaqas908)

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/waqassiwag-laravel-variant-generator/health.svg)

```
[![Health](https://phpackages.com/badges/waqassiwag-laravel-variant-generator/health.svg)](https://phpackages.com/packages/waqassiwag-laravel-variant-generator)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[illuminate/events

The Illuminate Events package.

13556.1M2.0k](/packages/illuminate-events)[illuminate/session

The Illuminate Session package.

9938.5M819](/packages/illuminate-session)[illuminate/pagination

The Illuminate Pagination package.

10533.5M986](/packages/illuminate-pagination)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.9M200](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.4M359](/packages/illuminate-redis)

PHPackages © 2026

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