I have 3 tables:
- users,
- jobs: id,user_id,name
- chats: id,job_id,name
I want to get chats depends on user's job. i've tried this one below, but i still get data from all chat, for example i want to get chat's data from user_id = 3:
$chat = Chat::with(['jobs' => function($query) use($userId){
$query->where('user_id',$userId);
}])->get();