2017 © Pedro Peláez
 

library laravel-configurable

Make your Eloquent models configurable.

image

signifly/laravel-configurable

Make your Eloquent models configurable.

  • Monday, May 14, 2018
  • by signifly
  • Repository
  • 3 Watchers
  • 2 Stars
  • 324 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1443 % Grown

The README.md

Easily make your Eloquent models configurable

Latest Version on Packagist Tests StyleCI Quality Score Total Downloads, (*1)

The signifly/laravel-configurable package allows you to easily make your Eloquent models configurable., (*2)

Below is a small example of how to use it., (*3)

// Remember to add use statement
use Signifly\Configurable\Configurable;

class User
{
    use Configurable;

    // Remember to make `config` fillable
    protected $fillable = [
        'config',
    ];

    // Remember to add `config` to casts
    protected $casts = [
        'config' => 'array',
    ];
}

Adding the column to your table migration:, (*4)

Schema::table('users', function (Blueprint $table) {
    $table->json('config')->nullable();
});

Now you would be able to configure your user model:, (*5)

$user = User::find(1);
$user->config()->some_key = 'some val';
$user->config()->set('some_other_key', 'some other val');
$user->save();

Retrieving from your config is straightforward:, (*6)

$user = User::find(1);
$user->config()->some_key; // returns some val
$user->config()->get('some_other_key'); // return some other val

Removing attributes from config can be done like this:, (*7)

$user = User::find(1);
$user->config()->remove('some_key');
$user->save();

Checking if an attribute exists in the config:, (*8)

$user = User::find(1);
$user->config()->has('some_key'); // returns true

Retrieving an attribute as a collection:, (*9)

$user = User::find(1);
$user->config()->collect('some_key'); // returns Collection(['some val']);

You can also overwrite the config key:, (*10)

// Remember to add use statement
use Signifly\Configurable\Configurable;

class User
{
    use Configurable;

    // Remember to make `settings` fillable
    protected $fillable = [
        'settings', 'extras',
    ];

    // Remember to add `settings` to casts
    protected $casts = [
        'settings' => 'array',
        'extras' => 'array',
    ];

    protected function getConfigKey()
    {
        return 'settings';
    }

    // or add a custom config attribute like this:
    public function getExtrasAttribute()
    {
        return new Config($this, 'extras');
    }
}

Documentation

Until further documentation is provided, please have a look at the tests., (*11)

Installation

You can install the package via composer:, (*12)

$ composer require signifly/laravel-configurable

The package will automatically register itself., (*13)

Testing

$ composer test

Security

If you discover any security issues, please email dev@signifly.com instead of using the issue tracker., (*14)

Credits

License

The MIT License (MIT). Please see License File for more information., (*15)

The Versions

14/05 2018

dev-master

9999999-dev https://github.com/signifly/laravel-configurable

Make your Eloquent models configurable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Morten Poul Jensen

14/05 2018

v1.0.2

1.0.2.0 https://github.com/signifly/laravel-configurable

Make your Eloquent models configurable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Morten Poul Jensen

14/05 2018

v1.0.1

1.0.1.0 https://github.com/signifly/laravel-configurable

Make your Eloquent models configurable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Morten Poul Jensen

14/05 2018

v1.0.0

1.0.0.0 https://github.com/signifly/laravel-configurable

Make your Eloquent models configurable.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Morten Poul Jensen