gpt4 book ai didi

php - $model->get() 返回软删除

转载 作者:搜寻专家 更新时间:2023-10-31 21:04:19 24 4
gpt4 key购买 nike

当我运行以下方法时,它返回一个包含软删除的集合......显然,它不应该。

return $twitter_oauth->get();

我认为这可能是我的 TwitterOAuth 模型中的引导函数。我使用下面的引导方法来软删除相关模型(正常工作)。

public static function boot()
{
TwitterOAuth::deleting(function($twitter_oauth) {
$twitter_oauth->posts()->delete();
});

TwitterOAuth::restoring(function($twitter_oauth) {
$twitter_oauth->posts()->withTrashed()->restore();
});
}

现在,如果我删除引导方法并运行相同的 get 查询,软删除不会出现在集合中。诡异的。任何人都遇到过或遇到过这个问题 - 或者看到我的问题?

我知道我可以在我的查询中使用 whereNull ,但这似乎是一个 hack。必须有更好的方法...

最佳答案

需要在我的引导方法中包含 parent::boot();。解决了。​​

public static function boot()
{
parent::boot();

TwitterOAuth::deleting(function($twitter_oauth) {
$twitter_oauth->posts()->delete();
});

TwitterOAuth::restoring(function($twitter_oauth) {
$twitter_oauth->posts()->withTrashed()->restore();
});
}

关于php - $model->get() 返回软删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35234925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com