Reputation: 89
owner
it's a column of bulletins
table which is relation in Conversations model.
public function bulletin()
{
return $this->belongsTo('App\Bulletins','bulletin_id');
}
$conversations = Conversations::with('bulletin','messages')
->where('owner_id', $userId)
->orWhere('owner', $userId)
->get();
I got unknown column owner. I know what it mean, but how to do this in laravel? Before I used left join for this request and now I want to use eloquent relations.
Upvotes: 1
Views: 47
Reputation: 14298
I don't understand why you have it twice? So is the column name owner
or owner_id
?
You should be able to do it like this:
$conversations = Conversations::with(['bulletin' => function($query) use ($userId) {
$query->where('owner_id', $userId);
}, 'messages'])->get();
Upvotes: 1