Download the PHP package secretwebmaster/laravel-optionable without Composer
On this page you can find all versions of the php package secretwebmaster/laravel-optionable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download secretwebmaster/laravel-optionable
More information about secretwebmaster/laravel-optionable
Files in secretwebmaster/laravel-optionable
Package laravel-optionable
Short Description Allow any Eloquent model to have own options such as user options, page options, etc.
License MIT
Homepage https://github.com/secretwebmaster/laravel-optionable
Informations about the package laravel-optionable
Laravel Optionable v2.1
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.
v2.1 is the Laravel 13 support line and targets:
- PHP 8.4+
- Laravel / Illuminate 13.x
- Orchestra Testbench 11.x for package testing
Installation
The package depends on secretwebmaster/wncms-translatable because option values use its translation trait internally.
Usage
Add HasOptions to any Eloquent model:
You may now store unlimited structured options on this model.
Getting Options
Get all rows (optional scope/group)
Returns a sorted Collection of Option rows.
Get a single option value
Or with group:
Fallback support:
Allow null values:
Setting Options
Set a single option
With group and sort:
Set multiple options for a scope/group
This clears existing options under that scope/group first.
Deleting Options
Delete a single option
With group and sort:
Clear all options under a scope/group
Table Schema (v2)
The migration creates:
| Column | Type | Description |
|---|---|---|
| id | bigint | primary key |
| scope | string nullable | Option namespace (e.g. theme/template/seo) |
| group | string nullable | Optional subgroup |
| key | string | Option key |
| sort | integer nullable | Repeatable index |
| value | text/json | Value (translated or raw) |
| is_translatable | boolean | Whether value uses HasTranslations |
| optionable_type | string | Morph type |
| optionable_id | bigint | Morph id |
| timestamps | — | — |
Indexes:
scope + group + key + sort + optionable_type + optionable_id- polymorphic indexes
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.
All versions of laravel-optionable with dependencies
illuminate/database Version ^13.0
illuminate/support Version ^13.0
secretwebmaster/wncms-translatable Version ^1.4.1