1$users = DB::table('users')
2 ->join('contacts', 'users.id', '=', 'contacts.user_id')
3 ->join('orders', 'users.id', '=', 'orders.user_id')
4 ->select('users.*', 'contacts.phone', 'orders.price')
5 ->get();
1DB::table('users')
2 ->select('users.*', DB::raw('count(orders.user_id) as count_by_user_id'))
3 ->join('orders' ,function($join){
4 $join->on('orders.user_id', '=', 'users.id');
5 })
6 ->groupBy('users.id')
7 ->orderBy('users.id', "DESC")
8 ->get();