Or Where With Eloquent in Laravel
Syntax
$response = Model::where('field_1','=','value_1')
->where(function ($query) {
$query->where('field_2','=','value_2')
->orWhere('field_2','=','value_3');
})
->get();
Use for Users Model
Example 1 :
$user_detail = User::where('mobile','=','XXXXXXXXXX')
->where(function ($query) {
$query->where('customer_type','=','DISTRIBUTOR')
->orWhere('customer_type','=','EMPLOYEE');
})
->get();
Example 2 :
$user_detail = DB::table('users')->where('mobile','=','XXXXXXXXXX')
->where(function ($query) use ($type1,$type2) {
$query->where('customer_type','=',$type1)
->orWhere('customer_type','=',$type2);
})
->get();
Example 3 :
$users = User::where('mobile','=','XXXXXXXXXX')
->where(function ($query) {
$query->where('customer_type','=','type1')
->orWhere('customer_type','=','type2');
})
->first();
0 Comments