added docblocks, contract, and service provider
This commit is contained in:
134
README.md
134
README.md
@@ -1,4 +1,118 @@
|
||||
Laravel Meta-Articles Package
|
||||
# Laravel Meta-Articles
|
||||
|
||||
[![Build Status][ico-build]][link-travis]
|
||||
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
|
||||
[![Latest Unstable Version][ico-unstable]][link-packagist]
|
||||
[![License][ico-license]][link-license]
|
||||
[![Total Downloads][ico-downloads]][link-packagist]
|
||||
[![Latest Stable Version][ico-stable]][link-packagist]
|
||||
|
||||
The Framework for Meta enabled Laravel models.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
Via Composer
|
||||
|
||||
``` bash
|
||||
$ composer require glmdev/meta
|
||||
```
|
||||
|
||||
### Update the Laravel Framework
|
||||
|
||||
Add the following provider to config/app.php
|
||||
|
||||
``` php
|
||||
'providers' => [
|
||||
Glmdev\Meta\MetaServiceProvider::class
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
When declaring a new model, extend the Meta model:
|
||||
|
||||
``` php
|
||||
<?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
|
||||
<?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, when you create a new model, a Post in this case, your function would look something like this:
|
||||
|
||||
``` php
|
||||
public function createPost () {
|
||||
$post = Post::create([
|
||||
// post data
|
||||
]);
|
||||
|
||||
$post->setUuid();
|
||||
}
|
||||
```
|
||||
|
||||
You now 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:
|
||||
``` php
|
||||
$post->hasUuid(); // returns true or false
|
||||
$post->getUuid(); // returns the UUID if it exists, else null
|
||||
```
|
||||
|
||||
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.
|
||||
``` php
|
||||
$post->write('author', 'Bob Saget');
|
||||
```
|
||||
|
||||
And to retrieve meta information, use the 'read' method.
|
||||
``` php
|
||||
$post->read('author'); //returns 'Bob Saget'
|
||||
```
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
- [Garrett Mills][link-author]
|
||||
- [All Contributors][link-contributors]
|
||||
|
||||
|
||||
## License and Copyright
|
||||
|
||||
Copyright (C) 2016 Garrett Mills
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -12,4 +126,20 @@ Laravel Meta-Articles Package
|
||||
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/>.
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Please see [License File][link-license] for more details.
|
||||
|
||||
[ico-stable]: https://poser.pugx.org/glmdev/meta/v/stable
|
||||
[ico-unstable]: https://poser.pugx.org/glmdev/meta/v/unstable
|
||||
[ico-downloads]: https://poser.pugx.org/glmdev/meta/downloads
|
||||
[ico-license]: https://poser.pugx.org/glmdev/meta/license
|
||||
[ico-scrutinizer]: https://scrutinizer-ci.com/g/glmdev/meta/badges/quality-score.png?b=master
|
||||
[ico-build]: https://travis-ci.org/glmdev/meta.svg
|
||||
|
||||
[link-travis]: https://travis-ci.org/glmdev/meta
|
||||
[link-packagist]: https://packagist.org/packages/glmdev/meta
|
||||
[link-scrutinizer]: https://scrutinizer-ci.com/g/glmdev/meta
|
||||
[link-license]: ./LICENSE
|
||||
[link-author]: https://github.com/glmdev
|
||||
[link-contributors]: ../../contributors
|
||||
Reference in New Issue
Block a user