Answers for "join laravel eloquent as"

PHP
18

laravel join

Inner Join 	: ->join('contacts', 'users.id', '=', 'contacts.user_id')
Left Join 	: ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
Right Join 	: ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
Cross Join 	: ->crossJoin('colors')

Advance Queries : 
----------------- 
 		->join('contacts', function ($join) {
            $join->on('users.id', '=', 'contacts.user_id')
                 ->where('contacts.user_id', '>', 5);
        })
Posted by: Guest on August-13-2020
3

laravel join

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();
Posted by: Guest on April-29-2020
0

join in eloquent laravel 5.8

->leftJoin('reg-session as rs', function ($q) use ($es) {
    $q->on('rs.regID', '=', 'event-registration.regID')
        ->on('rs.personID', '=', 'p.personID')
        ->on('rs.sessionID', '=', 'es.sessionID')
        ->where('es.sessionID', '=', $es->sessionID);
})
  
  
  $sub1 = DB::table('membership_years')
    ->select('member_id', DB::raw('MAX(membership_year) AS max_my'))
    ->groupBy('member_id');

$sub2 = DB::table('membership_years as my1')
    ->select('my1.*')
    ->join(DB::raw('(' . $sub1->toSql() . ') my2'),
            function ($join) {
                $join
                    ->on('my1.member_id', '=', 'my2.member_id')
                    ->on('my1.membership_year', '=', 'my2.max_my');
            });

$query = DB::table('membership as m')
    ->select('my.membership_year', 'm.*')
    ->join(DB::raw('(' . $sub2->toSql() . ') my'), 'm.id', '=', 'my.member_id')
    ->orderBy('m.id');
Posted by: Guest on April-06-2021

Browse Popular Code Answers by Language