public function scopeLatestInnerCommentDate($query) { $messageId = $reactionId = Carbon::today(); if (InnerComment::where('reaction_id', '0')->exists()) { $messageId = InnerComment::orderBy('post_date', 'DESC')->where('reaction_id', '0')->first()->post_date; } if (InnerComment::where('reaction_id', '!=', '0')->exists()) { $reactionId = InnerComment::orderBy('post_date', 'DESC')->where('reaction_id', '!=', '0')->first()->post_date; } return max($messageId, $reactionId); }