owner
是bulletins
表中的一列,是会话模型中的关系。
public function bulletin()
{
return $this->belongsTo('App\Bulletins','bulletin_id');
}
$conversations = Conversations::with('bulletin','messages')
->where('owner_id', $userId)
->orWhere('owner', $userId)
->get();
我有未知的列所有者。我知道这是什么意思,但是如何在laravel中执行此操作?在我使用左连接进行此请求之前,现在我想使用雄辩的关系。
答案 0 :(得分:1)
我不明白你为什么要两次?列名称是owner
还是owner_id
?
您应该可以这样做:
$conversations = Conversations::with(['bulletin' => function($query) use ($userId) {
$query->where('owner_id', $userId);
}, 'messages'])->get();