在关联关系中定义包含软删除内容:
public function roles() {
return $this->hasMany(Role::class)->withTrashed();
}
在模型列表中包含软删除内容:
$user->roles()->withTrashed()->get();
在预加载中包含软删除内容:
$user = User
::with(['roles' => fn($q) => $q->withTrashed()])
->findOrFail($id);
(adsbygoogle = window.adsbygoogle || []).push({});
来源:https://www.02405.com/archives/7435