Laravel 5.4 Zizaco/委托 - 用户软删除



我如何防止在用户软删除上脱离角色?
$user->hasRole('subscriber') => true
$user->delete()
$user->hasRole('subscriber') => false
$user->restore()
$user->hasRole('subscriber') => false

查看toverustusertrait行69-80。

/**
 * Boot the user model
 * Attach event listener to remove the many-to-many records when trying to delete
 * Will NOT delete any records if the user model uses soft deletes.
 *
 * @return void|bool
 */
public static function boot()
{
    parent::boot();
    static::deleting(function($user) {
        if (!method_exists(Config::get('auth.model'), 'bootSoftDeletes')) {
            $user->roles()->sync([]);
        }
        return true;
    });
}

我认为,如果您没有 bootsoftDeletes

class User extends Authenticatable
{
    use SoftDeletes;
    use EntrustUserTrait;
    ...

相关内容

  • 没有找到相关文章

最新更新