You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+74-1
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,8 @@ Laravel meta 2 has some backward incompatible changes that listed below:
66
66
67
67
#### Migration Table Schema
68
68
69
+
Each model needs its own meta table.
70
+
69
71
This is an example migration. you need change parts of it.
70
72
71
73
In this example we assume you have a model named `Post`.
@@ -344,7 +346,7 @@ $post->getMeta(['content', 'views'],'none');// result if the metas are missing:
344
346
$post->getMeta(['content', 'views']);// result if the metas are missing: ['content'=>null,'views'=>null]
345
347
```
346
348
347
-
#### Disable fluent access
349
+
#### Disable Fluent Access
348
350
349
351
If you don't want to access metas in fluent way, you can disable it by adding following property to your model:
350
352
@@ -408,3 +410,74 @@ You can also use it on eloquent relations.
408
410
/* Post model */
409
411
public $hideMeta = true; // Do not add metas to array
410
412
```
413
+
414
+
## Events
415
+
416
+
Laravel meta dispatches several events, allowing you to hook into the following events: `metaCreating`, `metaCreated`, `metaSaving`, `metaSaved`, `metaUpdating`, `metaUpdated`, `metaDeleting` and `metaDeleted`. Listeners should expect two parameters, first an instance of the model and second, name of the meta that event occurred for it. To enable events you need to add `HasMetaEvents` trait to your model:
417
+
418
+
```php
419
+
use Kodeine\Metable\Metable;
420
+
use Kodeine\Metable\HasMetaEvents;
421
+
use Illuminate\Database\Eloquent\Model;
422
+
423
+
class User extends Model
424
+
{
425
+
use Metable,HasMetaEvents;
426
+
}
427
+
```
428
+
429
+
After that, you can listen for events the [same way](https://laravel.com/docs/master/eloquent#events) you do for models.
430
+
431
+
> If you `return false;` in listener of any event ending with `ing`, that operation will be aborted.
0 commit comments