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
Informations about the package laravel-optionable
Laravel Optionable
Allow any Eloquent model to have flexible options (like user settings, page options, metadata, etc.).
Options are stored in a dedicated table and can be retrieved, updated, or deleted easily.
Installation
Install via Composer:
`
Run the migration to create the options
table:
That’s all you need 🎉
Overview
- Get all options
- Get single option value
- Set single option
- Set multiple options
- Delete single option
- Delete multiple options
- Delete all options
Usage
Add the HasOptions
trait to any Eloquent model.
Example: Post
model
Now you can manage options directly on the model instance:
Get all options
Get single option value
With fallback:
If you want to allow null
/empty values (instead of fallback):
Set single option
Set multiple options
Delete single option
Delete multiple options
Delete all options
Or keep some keys:
Legacy Support
For backward compatibility, all methods are also available in snake_case:
Both camelCase and snake_case will work ✅
Table Schema
The migration creates an options
table with:
id
key
(string)value
(json, nullable)optionable_type
(string)optionable_id
(unsignedBigInteger)timestamps
Constraints & Indexes:
- Unique per model:
optionable_type + optionable_id + key
- Indexed
key
column - Indexed polymorphic relation via
morphs()
License
MIT © secretwebmaster
All versions of laravel-optionable with dependencies
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0