laravel查询构建器中哪里不存在或哪里不同

时间:2014-04-25 18:59:18

标签: php laravel-4

我的查询检查字段是否为空或数据是否已经过验证:

return $this->with(array('funcionario', 'item_contabil'))
        ->where('tb_horario.cod_funcionario', $codfunc)
        ->whereBetween('tb_horario.data', array($datainicio, $datafinal))
        ->where('tb_horario.validado', 0)
        ->where('tb_horario.motivo','<>', '')
        ->orderBy('tb_horario.data')
        ->count();

我想知道在这一行中我是否可以在laravel 4中使用whereNot()或whereDifferent():

->where('tb_horario.motivo','<>', '')

存在类似的东西??? thxx!

1 个答案:

答案 0 :(得分:1)

你可以使用Laravel Query Builder做很多事情:

Docs(Advanced Wheres)

复制
->where('tb_horario.cod_funcionario', '=', 'John')
            ->orWhere(function($query) {
                $query->where('tb_horario.validado', '>', 100)
                      ->where('tb_horario.motivo', '<>', '');
            })->get();

或类似的东西

 ->where('tb_horario.cod_funcionario', '=', 'John')
            ->whereRaw('tb_horario.validado > 100');
            ->get();

Laravel提供了几种创建查询的选项......

whereNotIn
whereNotExists
whereExists
...

查看API-Docs。我相信你会找到适合你的东西。