如何获得相关的模型记录在laravel中通过模型trashed hasManyThrough关系
问题描述:
我有三种模型User
,Customer
,Message
。如何获得相关的模型记录在laravel中通过模型trashed hasManyThrough关系
在用户模式,我有:
public function customers()
{
return $this->hasMany(Customer::class);
}
public function messages()
{
return $this->hasManyThrough(Message::class, Customer::class);
}
,而我使用的客户模型softDeletes特质。
现在在我的控制器,而返回像这样
$messages = auth()->user()->messages()->paginate(30);
用户的邮件,我无法得到属于丢弃客户信息。
请提出解决方案。我没有在用户和消息模型中使用softDeletes。
答
hasManyThrough不支持softedelete函数,如withTrashed。
我想你应该尝试与另一种关系模型