Friday, July 24, 2015

Join Query for multiple condition in Laravel 5.1

Join Query for Multiple Condition:

For join query in multiple condition we will use it by the following way:

DB::table('users')
        ->join('contacts', function($join) use($userId)
        {
            $join->on('users.id', '=', 'contacts.user_id')
            ->where('contacts.user_id','=',$userId);
        })
        ->get();


Also sometime we need to use condition that field is null or field is not null in where condition so we can do the following

$users = DB::table('users')
                    ->whereNull('updated_at')
                    ->get();


Thanks.

No comments:

Post a Comment