Eloquent get by related table count
Eloquent get by related table count I created messenger for laravel. Now I wanna list all threads in which user is participating with a count of messages in each thread. I need the count to where clause because I want to show only these threads, in which are messages. where My current query: $threads = Participant::with('thread.messages') -> where('user_id', Auth::user() -> id) -> get(); $threads = Participant::with('thread.messages') -> where('user_id', Auth::user() -> id) -> get(); Participant: public function user() { return $this -> hasOne(User::class, 'id', 'user_id'); } public function thread() { return $this -> hasOne(Thread::class, 'id', 'thread_id'); } Thread: public function participants() { return $this -> hasMany(Participant::class, 'thread_id', 'id'); } function messages() { return $this -> hasMany(Message::class, 'thread_id', 'id')...