2017 © Pedro Peláez
 

library eloquent-meta

Attach meta data to Eloquent models

image

phoenix/eloquent-meta

Attach meta data to Eloquent models

  • Thursday, June 21, 2018
  • by chrismichaels84
  • Repository
  • 4 Watchers
  • 53 Stars
  • 28,499 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 18 Forks
  • 1 Open issues
  • 21 Versions
  • 4 % Grown

The README.md

This should be considered abandoned. It may not even work with newer versions of Laravel. I have moved on from Laravel and PHP. Any PR issued will be accepted w/o question. If you want to own this repository, open an issue and contact me., (*1)

Phoenix Eloquent Meta

Latest Version Software License Build Status Total Downloads, (*2)

Attach meta data to Laravel's Eloquent models. * Optionally create a separate table for each Model * Use with or without Laravel * Includes Laravel migrations or schema instructions * Get meta or fallback, (*3)

Which Version?
  • Lavavel 5.7 - use 1.9.*
  • Laravel 5.6 - use 1.8.*
  • Laravel 5.5 - use 1.7.*
  • Laravel 5.4 - Use 1.6.*
  • Laravel 5.3 - Use 1.5.*
  • Below 5.3 - Not technically supported, but should work with .1.3
  • Laravel 4 - Also not supported, but should work with 1.2
Stable Version: 1.4.* works with Laravel 5.* or independently. Pulls Eloquent in automatically.

To use for Laravel 4, see version 1.2.*, (*4)

Installation

Install through Composer., (*5)

"require": {
    "phoenix/eloquent-meta": "1.6.*"
}

Please note only php 5.6 and 7+ are supported., (*6)

If you are using EloquentMeta and Eloquent without using Laravel, you will also have to setup Eloquent as detailed in its documentation., (*7)

If you are using Laravel, then you'll want to include the ServiceProvider that will register commands and the like. Update config/app.php to include a reference to this package's service provider in the providers array., (*8)

'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]

Table Structure

If you are using Laravel, run the migration php artisan vendor:publish and php artisan migrate to create the database table., (*9)

If you are not using Laravel then you must create the table manually., (*10)

CREATE TABLE meta
(
    id INTEGER PRIMARY KEY NOT NULL,
    metable_id INTEGER NOT NULL,
    metable_type TEXT NOT NULL,
    key TEXT NOT NULL,
    value TEXT NOT NULL
);
CREATE UNIQUE INDEX meta_key_index ON meta (key);
CREATE UNIQUE INDEX meta_metable_id_index ON meta (metable_id);

Usage

Add the trait to all models that you want to attach meta data to:, (*11)

use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;

class SomeModel extends Model
{
    use MetaTrait;

    // model methods
}

Then use like this:, (*12)

$model = SomeModel::find(1);
$model->getAllMeta();
$model->getMeta('some_key', 'optional default value'); // default value only returned if no meta found.
$model->updateMeta('some_key', 'New Value');
$model->deleteMeta('some_key');
$model->deleteAllMeta();
$model->addMeta('new_key', ['First Value']);
$model->appendMeta('new_key', 'Second Value');

Unique Meta Models and Tables

You can also define a specific meta model for a meta type. For instance, your User model can use UserMeta model with custom methods and all. Using the example above:, (*13)

use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;

class SomeModel extends Model
{
    use MetaTrait;

    protected $meta_model = 'Fully\Namespaced\SomeModelMeta';

    // model methods
}

Then in SomeModelMeta simply extends Phoenix\EloquentMeta\Meta. You may now add custom methods to the meta model. You may also dictate which table the metadata is saved to by adding, (*14)

protected $table = "whatever_table";

If you are using EloquentMeta independent of Laravel, then you will have to create the database table manually., (*15)

If you are using Laravel, then include the service provider in your config/app.php, (*16)

'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]

Then run php artisan generate:metatable table_name to create the migration and run php artisan migrate to build the table., (*17)

Contributing

Please se [CONTRIBUTING.md] for more information and for testing., (*18)

Thank you and Credits

Contributors - Michael Wilson - @chrismichaels84 - Maintainer - Paweł Ciesielski - @dzafel - Lukas Knuth - @LukasKnuth - @stephandesouza, (*19)

Many thanks to Boris Glumpler and ScubaClick for the original package!, (*20)

The Versions

17/03 2015

v1.3.2

1.3.2.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

16/02 2015

v1.3.1

1.3.1.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

16/02 2015

v1.2.3

1.2.3.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

24/10 2014

1.2.5

1.2.5.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

22/10 2014

1.2.3

1.2.3.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

17/08 2014

v1.2.2

1.2.2.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Boris Glumpler

laravel eloquent meta

15/08 2014

v1.2.0

1.2.0.0 https://github.com/phoenix-labs/eloquent-meta

Attach meta data to Eloquent models

  Sources   Download

MIT

The Requires

 

by Boris Glumpler

laravel eloquent meta