Artesaos\Defender\Traits\Models\Permission::newPivot PHP Method

newPivot() public method

public newPivot ( Model $parent, array $attributes, string $table, boolean $exists ) : Artesaos\Defender\Pivots\PermissionUserPivot | Illuminate\Database\Eloquent\Relations\Pivot
$parent Illuminate\Database\Eloquent\Model
$attributes array
$table string
$exists boolean
return Artesaos\Defender\Pivots\PermissionUserPivot | Illuminate\Database\Eloquent\Relations\Pivot
    public function newPivot(Model $parent, array $attributes, $table, $exists)
    {
        $userModel = app()['config']->get('defender.user_model');
        $roleModel = app()['config']->get('defender.role_model');
        if ($parent instanceof $userModel) {
            return new PermissionUserPivot($parent, $attributes, $table, $exists);
        }
        if ($parent instanceof $roleModel) {
            return new PermissionRolePivot($parent, $attributes, $table, $exists);
        }
        return parent::newPivot($parent, $attributes, $table, $exists);
    }