我有一个社交网络类型网站,其中有正常的前端和管理界面供我登录。
我希望能够从前端排除所有软删除的记录(无论如何),但在管理员中我希望它们包含在每个查询中,因此我可以在列表中查看它们,编辑它们等等。
我尝试使用带有withTrashed方法的全局作用域,并尝试删除SoftDeletingScope作用域,但它们似乎都不起作用,但在使用查询构建器时它仍然排除了这些模型。 e.g。
/**
* The "booting" method of the user model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
if ( Auth::user()->isAdmin() ) {
static::addGlobalScope('showDeleted', function(Builder $builder) {
$builder->withTrashed();
});
// or
static::addGlobalScope('showDeleted', function(Builder $builder) {
$builder->removeGlobalScope(SoftDeletingScope::class);
});
}
}