PHPackages                             secretwebmaster/laravel-optionable - 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. [Database &amp; ORM](/categories/database)
4. /
5. secretwebmaster/laravel-optionable

ActiveLibrary[Database &amp; ORM](/categories/database)

secretwebmaster/laravel-optionable
==================================

Allow any Eloquent model to have own options such as user options, page options, etc.

v2.0.2(3mo ago)0137↓100%1MITPHPPHP ^8.2

Since Apr 27Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/secretwebmaster/laravel-optionable)[ Packagist](https://packagist.org/packages/secretwebmaster/laravel-optionable)[ RSS](/packages/secretwebmaster-laravel-optionable/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (4)Versions (11)Used By (1)

Laravel Optionable v2.0.0
=========================

[](#laravel-optionable-v200)

Laravel Optionable adds flexible, structured option storage to any Eloquent model. Options are stored in a dedicated table with support for:

- **scope** (e.g. `theme`, `template`, `seo`)
- **group** (e.g. section or nested context)
- **repeatable items** with `sort`
- **nested JSON option values**
- **fallbacks**
- **translation support (via HasTranslations)**

This package powers advanced option systems such as **WNCMS theme options**, **page template options**, and **model metadata**.

---

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

[](#installation)

```
composer require secretwebmaster/laravel-optionable
php artisan migrate
```

---

Usage
=====

[](#usage)

Add `HasOptions` to any Eloquent model:

```
use Illuminate\Database\Eloquent\Model;
use Secretwebmaster\LaravelOptionable\Traits\HasOptions;

class Page extends Model
{
    use HasOptions;
}
```

You may now store unlimited structured options on this model.

---

Getting Options
===============

[](#getting-options)

Get all rows (optional scope/group)
-----------------------------------

[](#get-all-rows-optional-scopegroup)

```
$rows = $page->getOptions();
$rows = $page->getOptions('theme');
$rows = $page->getOptions('theme', 'header');
```

Returns a sorted `Collection` of Option rows.

---

Get a single option value
-------------------------

[](#get-a-single-option-value)

```
$value = $page->getOption('title', 'theme');
```

Or with group:

```
$value = $page->getOption('button_text', 'theme', 'hero');
```

Fallback support:

```
$value = $page->getOption('color', 'theme', 'footer', 'default-color');
```

Allow null values:

```
$page->getOption('logo', 'theme', null, null, false);
```

---

Setting Options
===============

[](#setting-options)

Set a single option
-------------------

[](#set-a-single-option)

```
$page->setOption('title', 'Hello World', 'theme');
```

With group and sort:

```
$page->setOption('image', '/a.jpg', 'theme', 'gallery', 0);
$page->setOption('image', '/b.jpg', 'theme', 'gallery', 1);
```

---

Set multiple options for a scope/group
--------------------------------------

[](#set-multiple-options-for-a-scopegroup)

```
$page->setOptions('theme', 'hero', [
    ['key' => 'title', 'value' => 'Welcome'],
    ['key' => 'subtitle', 'value' => 'Enjoy'],
    ['key' => 'button_text', 'value' => 'Click'],
]);
```

This clears existing options under that scope/group first.

---

Deleting Options
================

[](#deleting-options)

Delete a single option
----------------------

[](#delete-a-single-option)

```
$page->deleteOption('title', 'theme');
```

With group and sort:

```
$page->deleteOption('image', 'theme', 'gallery', 1);
```

---

Clear all options under a scope/group
-------------------------------------

[](#clear-all-options-under-a-scopegroup)

```
$page->clearOptions('theme', 'hero');
```

---

Table Schema (v2)
=================

[](#table-schema-v2)

The migration creates:

ColumnTypeDescriptionidbigintprimary keyscopestring nullableOption namespace (e.g. theme/template/seo)groupstring nullableOptional subgroupkeystringOption keysortinteger nullableRepeatable indexvaluetext/jsonValue (translated or raw)is\_translatablebooleanWhether value uses HasTranslationsoptionable\_typestringMorph typeoptionable\_idbigintMorph idtimestamps——Indexes:

- `scope + group + key + sort + optionable_type + optionable_id`
- polymorphic indexes

Legacy Support (v1)
-------------------

[](#legacy-support-v1)

Snake\_case method names continue to work for all methods that still exist in v2, thanks to the \_\_call() snake\_case fallback.

Supported snake\_case aliases:

- get\_option()
- set\_option()
- get\_options()
- set\_options()
- delete\_option()
- clear\_options()

The following v1 methods have been removed and no longer exist:

- deleteOptions()
- deleteAllOptions() Therefore their snake\_case forms (delete\_options(), delete\_all\_options()) are not available.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance81

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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 ~66 days

Recently: every ~24 days

Total

10

Last Release

101d ago

Major Versions

v1.4.0 → v2.0.02025-12-07

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.4.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![secretwebmaster](https://avatars.githubusercontent.com/u/16463637?v=4)](https://github.com/secretwebmaster "secretwebmaster (14 commits)")

---

Tags

laravelSettingsoptionseloquentpreferencessecretwebmasterwncms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/secretwebmaster-laravel-optionable/health.svg)

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

###  Alternatives

[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

402385.8k5](/packages/rtconner-laravel-likeable)[rennokki/eloquent-settings

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

804.2k](/packages/rennokki-eloquent-settings)[klaude/eloquent-preferences

Preferences for Laravel Eloquent models

3016.5k](/packages/klaude-eloquent-preferences)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2467.2k](/packages/cviebrock-eloquent-typecast)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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