PHPackages                             igaster/laravel-model-options - 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. igaster/laravel-model-options

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

igaster/laravel-model-options
=============================

Store an Options array in a JSON column. Get/Set values as if they were seperate keys in the Database

v1.0.2(7y ago)11724MITPHPPHP &gt;=5.4.0CI failing

Since Dec 16Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/igaster/laravel-model-options)[ Packagist](https://packagist.org/packages/igaster/laravel-model-options)[ Docs](https://github.com/igaster/laravel-model-options.git)[ RSS](/packages/igaster-laravel-model-options/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Description
-----------

[](#description)

[![Laravel](https://camo.githubusercontent.com/7d48a347cda33127449307a1ba24bdebf76d226c4f2a1585285c8e968f2666a9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)[![Build Status](https://camo.githubusercontent.com/0f2bcd805f7d133d2c5420cfb9e88198b4e4d45f020ea408c905b4fe560a4cbd/68747470733a2f2f7472617669732d63692e6f72672f696761737465722f6c61726176656c2d6d6f64656c2d6f7074696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/igaster/laravel-model-options)[![Downloads](https://camo.githubusercontent.com/3d47aba6705518c69c8af58e7e21cf4232b18ea222a9e03dab3ffbb0c8f9caca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696761737465722f6c61726176656c2d6d6f64656c2d6f7074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/igaster/laravel-model-options)

A simple Trait to store an Options array in a JSON column. Get/Set values as if they were seperate keys in the Database

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

[](#installation)

Edit your project's `composer.json` file to require:

```
"require": {
    "igaster/laravel-model-options": "~1.0"
}

```

and install with `composer update`

How to use
----------

[](#how-to-use)

1. Define a JSON key with name 'options' in your migration file:

```
$table->json('options')->nullable();
```

note that older versions of mySql don't support the json type. In that case you can safely fallback to a string type:

```
$table->string('options')->nullable();
```

2. Use the Trait in the coresponding model:

    ```
     use \igaster\modelOptions\modelOptions;

    ```
3. Define the valid option keys in model:

    ```
     protected $validOptions=[
         'option_1',
         'option_2',
     ];

    ```

Usage:
------

[](#usage)

Access option key as if they were columns in your Database. eg:

```
    $model->option_1 = 'value1';

```

Handle Conflicts:
-----------------

[](#handle-conflicts)

This Trait makes use of the `__get()` and `__set()` magic methods to perform its ... well... magic! However if you want to implement these functions in your model or another trait then php will complain about conflicts. To overcome this problem you have to hide the Traits methods when you import it:

```
use igaster\modelOptions\modelOptions {
    __get as private;
    __set as private;
}
```

and call them manually from your `__get()` / `__set()` mehods:

```
//--- copy these in your model if you need to implement __get() __set() methods

public function __get($key) {
    // Handle modelOptions keys
    $result=$this->modelOptions_get($key);
    if ($this->modelOptions_handled)
        return $result;

    //your code goes here

    return parent::__get($key);
}

public function __set($key, $value) {
    // Handle modelOptions keys
    $this->modelOptions_set($key, $value);
    if ($this->modelOptions_handled)
        return;

    //your code goes here

    parent::__set($key, $value);
}
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance56

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

2835d ago

Major Versions

v0.1 → v1.02015-12-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/55bf1c9bc1f0553b439f18852299833373f96eb6c1342434c74fb61c5aecd508?d=identicon)[igaster](/maintainers/igaster)

---

Top Contributors

[![igaster](https://avatars.githubusercontent.com/u/4586319?v=4)](https://github.com/igaster "igaster (16 commits)")

---

Tags

laravelpackagetraitmodel settingssettings jsonmodel-optionsoptions-json

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/igaster-laravel-model-options/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k55.8M13.0k](/packages/illuminate-database)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[cybercog/laravel-love

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

1.2k341.5k1](/packages/cybercog-laravel-love)[lemaur/eloquent-publishing

218.5k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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