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(4mo ago)0137↓100%1MITPHPPHP ^8.2

Since Apr 27Pushed 4mo 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 1mo ago

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

41

—

FairBetter than 89% of packages

Maintenance74

Regular maintenance activity

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

148d 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

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M46](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)

PHPackages © 2026

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