您如何在laravel 5.4中编写此sql查询?

时间:2018-08-08 15:03:13

标签: php mysql laravel-5

        $user= Select from user where 'email' = $email AND 'specialty' =null OR 'address' = null OR 'country' =null OR 'state' = null;

这是我拥有的代码,但无法正常工作。我想要的是如果任何指定列的值都为null则返回该行。

    $doctor= Doctor::where('email',$email)->where(function ($query) {
            $query->orWhere('state','=','')
                  ->orWhere('country','=','')
                  ->orWhere('address','=','')
                  ->orWhere('specialty','=','');
        })->get();

1 个答案:

答案 0 :(得分:0)

第一件事-在SQL中以where x IS NOT NULL进行过滤的人应该使用whereNull

对于laravel部分,Eloquent有一种$doctor= Doctor::where('email',$email)->where(function ($query) { $query->orWhereNull('state') ->orWhereNull('country') ->orWhereNull('address') ->orWhereNull('specialty'); })->get(); 方法,请参见:https://laravel.com/docs/5.6/queries

所以您雄辩的代码应类似于:

const gulp = require('gulp');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const autoprefixer = require('gulp-autoprefixer');
const cssmin = require('gulp-cssmin');
const glob = require('glob');

// this gets an array of matching folders
const wpPluginFolders = glob.sync('lsmwp-*');

// for my testing I simplified the folder structure above, you would use
// const wpPluginFolders = glob.sync('wp-content/plugins/lsmwp-*');

const pluginSrc = '/assets/src/style.scss';

gulp.task('default', () => {

  let stream;

  // work on each folder separately
  wpPluginFolders.forEach(function (pluginFolder) {

    stream = gulp.src( pluginFolder + pluginSrc )
      .pipe(sass())
      .pipe(concat('style.min.css'))
      .pipe(autoprefixer())
      .pipe(cssmin())
      .pipe(gulp.dest( pluginFolder + '/assets/dist' ));
  });
  return stream;
});