Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Eloquent meta provides an easy way to implement schemaless meta data stores for Eloquent models.

License

Notifications You must be signed in to change notification settings

boxed-code/laravel-eloquent-meta

Repository files navigation

#Eloquent Meta#

Eloquent meta provides an easy way to implement schemaless meta data stores for Eloquent models.

Scrutinizer Code Quality Code Coverage Build Status

##Installation##

Add the package via composer:

composer require boxed-code/laravel-eloquent-meta

then add the following line to the providers key within your config/app.php file:

BoxedCode\Eloquent\Meta\MetaServiceProvider::class

You can then create a meta table migration using the artisan command:

php artisan make:meta-migration

and then call migrate

php artisan migrate

##Basic Usage##

There are two main methods of enabling a meta store on your models:

###Using the Metable trait### The Metable trait adds the basic meta store relation to your model so that it can be accessed like:

class MyModel extends Model
{
    use Metable;
}

...

$model = new MyModel();

// Access via magic accessors on the meta collection.

$model->meta->foo = 'bar';

echo $model->meta->foo; // prints 'bar'

// Access via the collection

$item = $model->meta->whereKey('foo')->first();

echo $item; // prints 'bar'

###Using the FluentMeta trait### The FluentMeta trait enables meta access on the model directly like:

use BoxedCode\Eloquent\Meta\FluentMeta;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    use FluentMeta;
}

...

$model = new MyModel();

// Access via magic accessors on the model.

$model->foo = 'bar';

echo $model->foo; // prints 'bar'

// Access via the collection

$item = $model->meta->whereKey('foo')->first();

echo $item; // prints 'bar'

##License## See the attached license file.

About

Eloquent meta provides an easy way to implement schemaless meta data stores for Eloquent models.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages