Php 如何在Laravel5.4中编写此sql查询?
这是我的代码,但它不能正常工作。我想要的是,如果声明的任何列的值为null,则返回该行Php 如何在Laravel5.4中编写此sql查询?,php,mysql,laravel-5,Php,Mysql,Laravel 5,这是我的代码,但它不能正常工作。我想要的是,如果声明的任何列的值为null,则返回该行 $user= Select from user where 'email' = $email AND 'specialty' =null OR 'address' = null OR 'country' =null OR 'state' = null; 第一件事优先-在SQL中,要按NULL进行筛选,应该使用,其中x不是NULL 对于laravel部分,Eloquent有一个whereNul
$user= Select from user where 'email' = $email AND 'specialty' =null OR 'address' = null OR 'country' =null OR 'state' = null;
第一件事优先-在SQL中,要按
NULL
进行筛选,应该使用,其中x不是NULL
对于laravel部分,Eloquent有一个whereNull
方法,请参阅更多:
因此,您雄辩的代码应该如下所示:
$doctor= Doctor::where('email',$email)->where(function ($query) {
$query->orWhere('state','=','')
->orWhere('country','=','')
->orWhere('address','=','')
->orWhere('specialty','=','');
})->get();
非常感谢。我不知道有一个orWhereNull()函数。我花了好几个小时在这上面。没问题,我很高兴能帮上忙。请参阅文档:
$doctor= Doctor::where('email',$email)->where(function ($query) {
$query->orWhereNull('state')
->orWhereNull('country')
->orWhereNull('address')
->orWhereNull('specialty');
})->get();