PHPackages                             mxrck/laravel-dboptions - 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. mxrck/laravel-dboptions

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

mxrck/laravel-dboptions
=======================

Create database based options for your laravel projects

v1.0.4(6y ago)01.6kPHP &gt;=7.1

Since Feb 23Compare

[ Source](https://github.com/Mxrck/laravel-dboptions)[ Packagist](https://packagist.org/packages/mxrck/laravel-dboptions)[ Docs](https://github.com/mxrck/laravel-dboptions)[ RSS](/packages/mxrck-laravel-dboptions/feed)WikiDiscussions Synced yesterday

READMEChangelogDependencies (1)Versions (7)Used By (0)

Laravel DB Options
==================

[](#laravel-db-options)

[![Build Status](https://camo.githubusercontent.com/346c465008c6abb3016dbddf7700fbddbdb92a5d63988edff156b5494fc0de65/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4d7872636b2f6c61726176656c2d64626f7074696f6e732f6d61737465722e737667)](https://travis-ci.org/Mxrck/laravel-dboptions/)

Use the database to store key/value options, with preload function and context objects with fallback to global options

### Install

[](#install)

```
composer require mxrck/laravel-dboptions
```

### Usage

[](#usage)

There are two ways to use the options store, by facade or helpers

#### Simple facade usage

[](#simple-facade-usage)

If you only need a database key/value to store data, then you can use the simplest way

```
// Get an option from the database or fallback to default
Options::get( 'somekey', 'default value' ); // if you need to reload from database then pass a third boolean argument with true

// Update or create (if not exists) an option
Options::update( 'somekey', 'somevalue' ); // If you want to autoload the option then pass a third array argument like ['autoload' => true]

// Check if an option is already stored in the database
Options::exists( 'somekey' );

// Delete an option from the database
Options::remove( 'somekey' );

// Get all options as array
Options::all();

/* this method return an array like this */
$all_options = [
    'somekey' => [
        'value'     => 'THE_VALUE_STORED',
        'autoload'  => false,
        'public'    => false
    ],
    ...
];

// Get all public options as array
Options::public(); // same as before, but only public options
```

### Simple helper usage

[](#simple-helper-usage)

```
// Get options instance
$options = option();
/* With $options you have all facade methods available to use */
/*
 * options()->get(...); options()->update(...); options()->exists(...); ...
 */

 // Get and option from database or fallback to default
 option('somekey')

 // Update or create (if not exists) an option
 option_update( 'somekey', 'somevalue' );

 // Check if option exists
 option_exists( 'somekey' );

 // Delete an option
 option_remove( 'somekey' );
```

### Context usage

[](#context-usage)

*This feature was requested by [@atxy2k](https://github.com/atxy2k)*

If you need a more advanced usage, like set options per user, with fallback to default option system or fallback to a default value, then you can use an option context. This contexts make use of polymorphic relations to create specific options, you can make any model to be optionable if you wish.

You need to implement the OptionableInterface, and use the OptionableTrait in the model you want to be optionable like this.

```
// User.php
use Illuminate\Database\Eloquent\Model;

class User extends Model implements OptionableInterface
{
    use OptionableTrait;
}
```

In the case you customize your morph map, you need to override and extra method in your model

```
// Provider
use Illuminate\Database\Eloquent\Relations\Relation;

Relation::morphMap([
    'user' => 'App\User'
]);

// User.php
use Illuminate\Database\Eloquent\Model;

class User extends Model implements OptionableInterface
{
    use OptionableTrait;

    public function getType(): string
    {
        return 'user';
    }
}
```

now you can use the facade or helpers with an optionable context like this

```
$user = User::find(10);

$user->option( 'somekey' ); // By default, from an optionable instance you can call options with the optionable context

// Or you can use the facade and helper with custom context
$value = Option::context( option_context( $user ) )->get( 'somekey' );
// Or
$value = Option::context( Context::make( $user ) )->get( 'somekey' );
// Or
$value = Option::context( $user )->get( 'somekey' );
// Or
$value = option( option_context( $user ) )->get( 'somekey' );
// Or
$value = option( $user )->get( 'somekey' );
```

Some examples

```
option( $user )->get( 'some_option' );
// return null

option( 'some_option');
// return null

option( $user )->update( 'some_option', 'user_value' );
// return 'user_value'
option( $user )->get( 'some_option' );
// return 'user_value'

option()->update( 'some_option', 'system_value' );
// return 'system_value'
option( 'some_option' )
// return 'system_value'

echo 'System: ' option( 'some_option' ) . ' User: '. option( $user )->get( 'some_option' );
// System: system_value User: user_value

// Fallback example:

option()->update( 'color', '#fffff' );
option( option_context( $user ) )->get( 'color' );
// return null
option( option_context( $user, true ) )->get( 'color' );
// return #ffffff

// Or using your model:
$user->optionFallback( 'color' );
// return #ffffff

// By default, context fallback is false
```

There are some hidden features undocumented yet, but the basic usage is here

### Console

[](#console)

#### Create or update an option

[](#create-or-update-an-option)

```
php artisan option:update {KEY} {VALUE}
```

#### Get an option

[](#get-an-option)

```
php artisan option:get {KEY}
```

#### List all current options

[](#list-all-current-options)

```
php artisan option:all
```

### Testing

[](#testing)

```
composer test
```

### WIP

[](#wip)

There are no Context testing yet

### Contributing

[](#contributing)

Thanks in advance, for all the contributions

### Support me

[](#support-me)

You can [follow me on Twitter](https://twitter.com/_mxrck), [buy me a coffee](https://www.paypal.me/animechannel/5usd) or [support me on Patreon](https://www.patreon.com/user?u=859275)

### License

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

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

Total

5

Last Release

2505d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b187206fcb01c69c5c2f174dd46b5676f1471dc3ff238c062dd9ca92e0ddb4f1?d=identicon)[Mxrck](/maintainers/Mxrck)

---

Top Contributors

[![Mxrck](https://avatars.githubusercontent.com/u/2360493?v=4)](https://github.com/Mxrck "Mxrck (6 commits)")

---

Tags

laraveloptionsdatabase

### Embed Badge

![Health badge](/badges/mxrck-laravel-dboptions/health.svg)

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

###  Alternatives

[nunomaduro/laravel-optimize-database

Publishes migrations that make your database production ready.

26441.3k](/packages/nunomaduro-laravel-optimize-database)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

525.8k](/packages/hpolthof-laravel-translations-db)[cubettech/lacassa

Cassandra based query builder for laravel.

348.6k](/packages/cubettech-lacassa)[codengine/laravel-custom-migrations

Custom Migrations for Laravel

131.3k](/packages/codengine-laravel-custom-migrations)

PHPackages © 2026

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