added custom migration generator artisan command
This commit is contained in:
72
README.md
72
README.md
@@ -1,7 +1,5 @@
|
||||
# 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]
|
||||
@@ -48,27 +46,17 @@ class Post extends Meta
|
||||
|
||||
> *Important*: do not extend the Model class, Meta does this for you
|
||||
|
||||
Then, include the 'meta' and 'uuid' columns in your database table:
|
||||
The Meta plugin adds a custom Artisan command to auto-generate migrations for meta-enabled models.
|
||||
To generate a migration for a new meta-model, use the following command:
|
||||
|
||||
In your migration,
|
||||
``` php
|
||||
<?php
|
||||
```
|
||||
php artisan meta:migration name_of_migration --create=table_name
|
||||
```
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
Add your custom fields, if any, then migrate as usual:
|
||||
|
||||
use Glmdev\Meta\Meta;
|
||||
|
||||
class CreatePostsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('posts', function (Blueprint $table) {
|
||||
// all your table values
|
||||
Meta::formTable($table);
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
php artisan migrate
|
||||
```
|
||||
|
||||
Then, just create a model like usual:
|
||||
@@ -102,6 +90,50 @@ And to retrieve meta information, use the 'read' method.
|
||||
$post->read('author'); //returns 'Bob Saget'
|
||||
```
|
||||
|
||||
### Adding Meta functionality to existing models
|
||||
|
||||
To add Meta capabilities to existing models, you need to add the database columns and tweak the model's class as follows:
|
||||
|
||||
##### Database update
|
||||
|
||||
Create a new database migration using the custom Meta command:
|
||||
|
||||
```
|
||||
php artisan meta:migration --table=existing_table_name
|
||||
```
|
||||
|
||||
Make sure the inside of the `up()` function matches the following:
|
||||
|
||||
``` php
|
||||
public function up()
|
||||
{
|
||||
Schema::table('DummyTable', function (Blueprint $table) {
|
||||
Meta::formTable($table);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Then, migrate:
|
||||
|
||||
```
|
||||
php artisan migrate
|
||||
```
|
||||
|
||||
##### Model Class updates
|
||||
|
||||
To enable the database functionality, the class for the model needs to extend the Meta class. Modify the class header to the following format:
|
||||
|
||||
``` php
|
||||
|
||||
class ClassNameHere extends Meta {
|
||||
// your class stuff here
|
||||
}
|
||||
```
|
||||
|
||||
> *Important*: you no longer need to extend the Model class, Meta does this for you
|
||||
|
||||
After that, you can use the full meta functionality with your model.
|
||||
|
||||
### 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)
|
||||
|
||||
Reference in New Issue
Block a user