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.
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