-1
如何防止用戶軟刪除角色分離?
$user->hasRole('subscriber')
=>真
$user->delete()
$user->hasRole('subscriber')
=>假
$user->restore()
$user->hasRole('subscriber')
=>假Laravel 5.4 Zizaco /委託 - 用戶軟刪除
如何防止用戶軟刪除角色分離?
$user->hasRole('subscriber')
=>真
$user->delete()
$user->hasRole('subscriber')
=>假
$user->restore()
$user->hasRole('subscriber')
=>假Laravel 5.4 Zizaco /委託 - 用戶軟刪除
看EntrustUserTrait行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;
});
}
我想你不使用Laravel自身SoftDeletes特質,如果你還沒有bootSoftDeletes。
class User extends Authenticatable
{
use SoftDeletes;
use EntrustUserTrait;
...