PHPackages                             fomvasss/laravel-static-lists - 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. fomvasss/laravel-static-lists

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

fomvasss/laravel-static-lists
=============================

Laravel bridge for fomvasss/static-lists: trait, Collection macros, helpers.

1.1.0(3mo ago)1356↓33.3%MITPHPPHP ^8.1

Since Oct 19Pushed 3mo agoCompare

[ Source](https://github.com/fomvasss/laravel-static-lists)[ Packagist](https://packagist.org/packages/fomvasss/laravel-static-lists)[ RSS](/packages/fomvasss-laravel-static-lists/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

fomvasss/laravel-static-lists
=============================

[](#fomvassslaravel-static-lists)

[![License](https://camo.githubusercontent.com/3f4ef75326a584ca639bcfede64d0cef5771132788e361c6e77d7596d79b7c8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6d76617373732f6c61726176656c2d7374617469632d6c697374732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-static-lists)[![Build Status](https://camo.githubusercontent.com/8ea3d94886797db8e082483966e16451a6f18ad36c2e4299d07a0d58e9890dcd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f666f6d76617373732f6c61726176656c2d7374617469632d6c697374732e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/fomvasss/laravel-static-lists)[![Latest Stable Version](https://camo.githubusercontent.com/8d2182b0ba9305b67fe6d6669d855c8ba5f61a27ecaec77ded945b59418659a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6d76617373732f6c61726176656c2d7374617469632d6c697374732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-static-lists)[![Total Downloads](https://camo.githubusercontent.com/e011a248f6bb1f65ccd04e5ada20c31622a9bfbc55571bcbe88e7be57a80ed8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6d76617373732f6c61726176656c2d7374617469632d6c697374732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-static-lists)

Laravel bridge for `fomvasss/laravel-static-lists`.

Deterministic list builder for arrays/iterables for Laravel.

Install
-------

[](#install)

`composer require fomvasss/laravel-static-lists`

Usage
-----

[](#usage)

```
use Fomvasss\LaravelStaticLists\Traits\HasStaticLists;

class Order extends Model {
    use HasStaticLists;

    public static function map(): array
    {
        return static::staticListBuild(static::$records, 'label', 'value', [
            'only' => ['paid','new'], 'sort' => 'priority'
        ]);
    }
}

// Or collection
collect($records)->listBuild('label', 'value', ['except' => ['done']]);
```

### Usage examles

[](#usage-examles)

```
use Fomvasss\LaravelStaticLists\Traits\HasStaticLists;

class Order extends Model
{
    use HasStaticLists;

    protected static array $statusRecords = [
        ['value' => 'new',     'label' => 'Новий',      'priority' => 30],
        ['value' => 'paid',    'label' => 'Оплачено',   'priority' => 10],
        ['value' => 'shipped', 'label' => 'Відправлено','priority' => 20],
        ['value' => 'done',    'label' => 'Завершено',  'priority' => 40],
        ['value' => 'done',    'label' => 'Завершено DUP', 'priority' => 40], // дубль для прикладу unique
    ];

    public static function statusesList(string $columnKey = null, string $indexKey = null, array $options = []): array
    {
        return self::staticListBuild(self::$statusRecords, $columnKey, $indexKey, $options);
    }

    // 1) Карта value => label
    public static function map(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value'
        );
        // ['new'=>'Новий','paid'=>'Оплачено','shipped'=>'Відправлено','done'=>'Завершено DUP'] (через останній дубль)
    }

    // 2) Тільки label як список (без ключів)
    public static function labels(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label'
        );
        // ['Новий','Оплачено','Відправлено','Завершено','Завершено DUP']
    }

    // 3) only з збереженням порядку
    public static function onlyPaidThenNew(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: '*',
            indexKey: 'value',
            options: ['only' => ['paid','new']]
        );
        // ['paid'=>['value'=>'paid',...],'new'=>['value'=>'new',...]]
    }

    // 4) except (виключити значення)
    public static function withoutFinal(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value',
            options: ['except' => ['done']]
        );
        // ['new'=>'Новий','paid'=>'Оплачено','shipped'=>'Відправлено']
    }

    // 5) added='*' (додати всі можливі, якщо попередньо відфільтровано only)
    public static function onlyPaidPlusAll(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value',
            options: [
                'only'  => ['paid'], // стартовий набір
                'added' => ['*'],    // додати все інше
                // за замовчуванням existing має пріоритет (override=false)
            ]
        );
        // Вихід: всі статуси, при конфліктах — зберігається існуючий 'paid'
    }

    // 6) added із override=true (додані заміщують існуючі)
    public static function overrideExample(): array
    {
        // Уявімо, що в allRecords є альтернативний label для 'paid'
        $all = array_map(fn($r) => $r, static::$statusRecords);
        $all[] = ['value'=>'paid','label'=>'Оплачено (ALT)','priority'=>15];

        return static::staticListBuild(
            $all,
            columnKey: 'label',
            indexKey: 'value',
            options: [
                'only'     => ['paid'],
                'added'    => ['paid','shipped'],
                'override' => true,
            ]
        );
        // ['paid'=>'Оплачено (ALT)','shipped'=>'Відправлено']
    }

    // 7) Сортування за полем (priority asc/desc)
    public static function sortedAsc(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value',
            options: ['sort' => 'priority', 'order' => 'asc']
        );
        // Порядок ключів: paid(10), shipped(20), new(30), done(40), done(40)
    }

    public static function sortedDesc(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value',
            options: ['sort' => 'priority', 'order' => 'desc']
        );
        // Порядок ключів: done(40), done(40), new(30), shipped(20), paid(10)
    }

    // 8) Сортування кастомним компаратором (done завжди вкінці)
    public static function customSort(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: 'value',
            options: [
                'sort' => function ($a, $b) {
                    $rank = fn($v) => $v === 'done' ? 999 : 0;
                    return ($rank($a['value'])  $rank($b['value']))
                        ?: (($a['priority'] ?? 0)  ($b['priority'] ?? 0));
                },
            ]
        );
        // done в кінці, інші — за priority
    }

    // 9) unique по indexKey
    public static function uniqueByValue(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: '*',
            indexKey: 'value',
            options: ['unique' => true]
        );
        // дубль 'done' прибрано; ключі унікальні
    }

    // 10) Отримати асоціативний масив по ключу (без columnKey)
    public static function indexByValue(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: null,
            indexKey: 'value'
        );
        // ['new'=>[...], 'paid'=>[...], 'shipped'=>[...], 'done'=>[...]] (останній дубль перемагає)
    }

    // 11) Chain: only + except + sort + повернути лише labels
    public static function chain(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'label',
            indexKey: null,
            options: [
                'only'   => ['paid','new','done','shipped'],
                'except' => ['new'],
                'sort'   => 'priority',
                'order'  => 'asc',
            ]
        );
        // ['Оплачено','Відправлено','Завершено','Завершено DUP']
    }

    // 12) Витягнути значення одного поля як список ID (наприклад для select)
    public static function valuesOnly(): array
    {
        return static::staticListBuild(
            static::$statusRecords,
            columnKey: 'value'
        );
        // ['new','paid','shipped','done','done']
    }
}
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance78

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~30 days

Total

4

Last Release

115d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f99b460639e7d6871597882226b1e0d9e3055992eac8b22bfcd4f90fbdac95c?d=identicon)[fomvasss](/maintainers/fomvasss)

---

Top Contributors

[![fomvasss](https://avatars.githubusercontent.com/u/19834478?v=4)](https://github.com/fomvasss "fomvasss (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fomvasss-laravel-static-lists/health.svg)

```
[![Health](https://phpackages.com/badges/fomvasss-laravel-static-lists/health.svg)](https://phpackages.com/packages/fomvasss-laravel-static-lists)
```

###  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)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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