本文介绍了雄辩的morphTo()-> withTrashed()停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OrderItem 模型中建立了多态关系,其中 saleable 可以是几个不同的模型.

I have a polymorphic relationship set up in an OrderItem model, where saleable can be a few different models.

我已将其设置为其他关系:

I've set it up like any other relationship:

public function saleable()
{
    return $this->morphTo()->withTrashed();
}

这曾经很好用,现在突然不起作用,并引发错误:

This used to work fine, now all of a sudden it doesn't work and it throws the error:

Call to undefined method Illuminate\Database\Query\Builder::withTrashed()

我不明白为什么它可能会停止工作,可能是由于作曲家的更新可能已经更新了Laravel.我正在使用v5.2.35.知道为什么它会停止工作以及我还有什么其他解决方案吗?

I don't understand why it would have stopped working, possibly due to a composer update which may have updated Laravel. I'm on v5.2.35. Any idea why it would have stopped working and what other solutions do I have?

更新

在v5.2.33及更早版本中可以正常工作.可能是一个错误,我在github上打开了一个问题

Works fine with v5.2.33 and earlier. May be a bug, I've opened an issue on github

推荐答案

我唯一能想到的就是您删除了该对象的SoftDelete特征,因此不再加载它,或者您添加了 boot 不从父级继承的方法(因此不会从此特征加载正确的方法)

The only thing I could imagine is that you removed SoftDelete trait for the object, so it's not loaded any more or you've added boot method that doesn't inherit from parent (so it won't load proper methods from this trait)

编辑

这似乎是v5.2.34中引入的错误.它似乎在此PR中得到了修复 https://github.com/laravel/framework/pull/13828

It seems to be a bug introduced in v5.2.34. It seems to be fixed in this PR https://github.com/laravel/framework/pull/13828

编辑

此刻应固定.v5.2.36已发布.

It should be fixed at the moment. v5.2.36 has been released.

这篇关于雄辩的morphTo()-> withTrashed()停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 16:46