PHPackages                             chrisabey84/laravel-cached-options-list - 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. [Caching](/categories/caching)
4. /
5. chrisabey84/laravel-cached-options-list

ActiveLibrary[Caching](/categories/caching)

chrisabey84/laravel-cached-options-list
=======================================

A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms

0.1(4y ago)0305[3 PRs](https://github.com/chrisabey84/laravel-cached-options-list/pulls)MITPHPPHP ^8.0

Since Jul 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/chrisabey84/laravel-cached-options-list)[ Packagist](https://packagist.org/packages/chrisabey84/laravel-cached-options-list)[ Docs](https://github.com/chrisabey84/laravel-cached-options-list)[ RSS](/packages/chrisabey84-laravel-cached-options-list/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (12)Versions (5)Used By (0)

Cache all the rows in a relationship model as a select array for use in forms
=============================================================================

[](#cache-all-the-rows-in-a-relationship-model-as-a-select-array-for--use-in-forms)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ea4cf3a23f7a1a9950cdd8f73cc2a47363ecaa2742b90a96e5a9197d0912c928/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63687269736162657938342f6c61726176656c2d6361636865642d6f7074696f6e732d6c6973742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chrisabey84/laravel-cached-options-list)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0c32883b825ca9435c193f5046974a6acc51f42cce1ecef3aa084e45525403c2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63687269736162657938342f6c61726176656c2d6361636865642d6f7074696f6e732d6c6973742f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/chrisabey84/laravel-cached-options-list/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/33bb93a9b0dfdaaec46edecde19de3a2899fc911b41154b7e0f1815e52863adb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f63687269736162657938342f6c61726176656c2d6361636865642d6f7074696f6e732d6c6973742f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/chrisabey84/laravel-cached-options-list/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b2b7681a9838f13648d7ce6a05dd82ed0d0e1ab357455d09330588d41f7efb79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63687269736162657938342f6c61726176656c2d6361636865642d6f7074696f6e732d6c6973742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chrisabey84/laravel-cached-options-list)

A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms.

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

[](#installation)

You can install the package via composer:

```
composer require chrisabey84/laravel-cached-options-list
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Chrisabey84\LaravelCachedOptionsList\LaravelCachedOptionsListServiceProvider
```

This is the contents of the published config file:

```
return [
    'key' => 'id', //The index/key column for the select options array
    'value' => 'name', //The value column for the select options array
];
```

Usage
-----

[](#usage)

Adding the `HasCachedOptionsList` trait to any of your models will provide the following functionality:

```
$rows = \App\Models\MyModel::asSelectArray();
```

Will retrieve all rows as an associative array which can then be used in your blade templates to populate the option in a select box:

```

@foreach($rows as $key => $value)
	{{ $value }}
@endforeach

```

### Custom Behavior

[](#custom-behavior)

By default `asSelectArray()` will retrieve all rows from the database table however, you can customise this behavior by overriding the following method in your model which must return a `Builder` instance:

```
protected static function buildQuery(): Builder
{
	return static::query();
}
```

### Clearing The Cache

[](#clearing-the-cache)

The cache will be automatically cleared when creating, updating or deleting your models.

To manually clear the cache, you can either call:

```
\App\Models\MyModel::clearOptionsCache();
```

Or use the handy artisan command with the model name as the argument:

```
php artisan cached-options:clear '\App\Models\MyModel'
```

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Christopher Abey](https://github.com/chrisabey84)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

1507d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/853422882a2329d6bf0bafdd4082ff46c53779db498482209cae6663ed0be4af?d=identicon)[chrisabey](/maintainers/chrisabey)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")[![chrisabey84](https://avatars.githubusercontent.com/u/59964241?v=4)](https://github.com/chrisabey84 "chrisabey84 (4 commits)")

---

Tags

laravelchrisabey84laravel-cached-options-list

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/chrisabey84-laravel-cached-options-list/health.svg)

```
[![Health](https://phpackages.com/badges/chrisabey84-laravel-cached-options-list/health.svg)](https://phpackages.com/packages/chrisabey84-laravel-cached-options-list)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M323](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[moonshine/moonshine

Laravel administration panel

1.3k268.2k89](/packages/moonshine-moonshine)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

8516.9k](/packages/yangusik-laravel-balanced-queue)

PHPackages © 2026

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