You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jake Mitchell 110ff0a15c
Allow users to write multiple items at once
8 years ago
src Allow users to write multiple items at once 8 years ago
tests Allow users to write multiple items at once 8 years ago
.gitignore added docblocks, contract, and service provider 8 years ago
.scrutinizer.yml added docblocks, contract, and service provider 8 years ago
.travis.yml added docblocks, contract, and service provider 8 years ago
LICENSE master 3 8 years ago
README.md added uuid query scope 8 years ago
composer.json added tests 8 years ago
contributors.txt added docblocks, contract, and service provider 8 years ago
phpunit.php added tests 8 years ago
phpunit.xml added docblocks, contract, and service provider 8 years ago

README.md

Laravel Meta-Articles

Build Status Quality Score Latest Unstable Version License Total Downloads Latest Stable Version

The Framework for Meta enabled Laravel models.

Install

Via Composer

$ composer require glmdev/meta

Update the Laravel Framework

Add the following provider to config/app.php

'providers' => [
    Glmdev\Meta\MetaServiceProvider::class
]

Usage

When declaring a new model, extend the Meta model:

<?php

namespace App;

use Glmdev\Meta\Meta;

class Post extends Meta 
{
    // fillable, hidden, etc. arrays
}

Important: do not extend the Model class, Meta does this for you

Then, include the 'meta' and 'uuid' columns in your database table:

In your migration,

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

use Glmdev\Meta\Meta;

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            // all your table values
            Meta::formTable($table);
        });
    }
}

Then, just create a model like usual:

public function createPost () {
    $post = Post::create([
        // post data
    ]);
}

But now, you have access to a universal identifier for every model in the entire project.

You can check if a model has a UUID, and get it if it does:

$post->hasUuid(); // returns true or false
$post->getUuid(); // returns the UUID

The other big feature of the Meta model is saving meta information. This information is stored in the database in one column: 'meta'

To save meta information, use the 'write' method.

$post->write('author', 'Bob Saget');

And to retrieve meta information, use the 'read' method.

$post->read('author'); //returns 'Bob Saget'

Query Builder

Let's say you need to retrieve the post that has a certain UUID (maybe you gave it out in a url or something)

It's super easy to search for it:

Post::withUuid($uuid)->first();

It is completely integrated into the query builder, so you can still do stuff like:

Post::withUuid($uuid)->pluck('username');
Post::withUuid($uuid)->firstOrFail();

Credits

Copyright (C) 2016 Garrett Mills

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Please see License File for more details.