Advertisement
AVONnadozie

Sample eloquent subquery using from

Jul 25th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. \App\Comment::select('comments.user_id', 'topics.id', 'topics.name')
  2.         ->from(DB::raw("(select * from comments where removed = 0 order by id desc) as comments"))
  3.         ->join('topics', 'comments.topic_id', 'topics.id')
  4.         ->whereIn('topics.cat_id', $cats)
  5.         ->where('topics.removed', false)
  6.         ->groupBy('topics.id')
  7.         ->limit(5)
  8.         ->get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement