PHP code example of signifly / laravel-pivot-events
1. Go to this page and download the library: Download signifly/laravel-pivot-events library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
signifly / laravel-pivot-events example snippets
// Remember to add use statement
use Signifly\PivotEvents\HasPivotEvents;
class User
{
use HasPivotEvents;
}
use Signifly\PivotEvents\HasPivotEvents;
class User
{
use HasPivotEvents;
protected static function boot()
{
static::pivotAttaching(function ($model) {
// To get related changes
$model->getPivotChanges();
// return Collection(['attach' => ['roles' => [1 => ['scopes' => 'orders']]]])
// To get related changes for a specific type
$model->getPivotChanges('attach');
// return Collection(['roles' => [1 => ['scopes' => 'orders']]])
// You can get nested changes
// values are $id => $attributes
$model->getPivotChanges('attach.roles');
// return Collection([1 => ['scopes' => 'orders']])
// To get related ids for a specific type and relation
$model->getPivotChangeIds('attach', 'roles');
// return Collection([1])
});
static::pivotAttached(function ($model) {
//
});
static::pivotDetaching(function ($model) {
//
});
static::pivotDetached(function ($model) {
//
});
static::pivotUpdating(function ($model) {
//
});
static::pivotUpdated(function ($model) {
//
});
}
}