Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1.  
  2.     public static function getCompanyUnread(int $companyId)
  3.     {
  4.         return Channel::select(['channels.offer_id', DB::raw('COUNT(distinct messages.channel_id) as count_messages')])
  5.             ->leftJoin('messages','messages.channel_id', '=', DB::raw('channels.id AND messages.author != "system"'))
  6.             ->where('channels.company_id', $companyId)
  7.             ->where(function ($query) {
  8.                 return $query->where('channels.employer_read_time', '<', DB::raw('messages.twilio_created_at'))
  9.                     ->orWhereNull('channels.employer_read_time');
  10.             })
  11.             ->groupBy('channels.offer_id')
  12.             ->get()
  13.             ;
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement