拉拉维尔查询生成器在哪里是空没有结果



我有如下代码来获取未NULLpdf_url的货件数据;

$shipment_data = DB::table('shipment')->where([
'shipment_date' => '2017-12-11', ['pdf_url', '<>', 'NULL']])->get();

这没有问题,我得到了我需要的数据,但是当我尝试使用相同的代码来获取数据时,pdf_urlNULL,它没有结果。

$shipment_data = DB::table('shipment')->where([
'shipment_date' => '2017-12-11', ['pdf_url', '=', 'NULL']])->get();

我错过了什么?我非常确定数据库记录在那里。我也尝试了其他格式,但仍然没有结果;

$shipment_data = DB::table('shipment')->where([
'shipment_date' => '2017-12-11', ['pdf_url', 'NULL']])->get();

$shipment_data = DB::table('shipment')->where([
'shipment_date' => '2017-12-11', 'pdf_url' => 'NULL'])->get();

编辑:我可以使用whereRaw,但我更喜欢使用where。下面的代码没有问题;

$shipment_data = DB::table('shipment')
->whereRaw('shipment_date = "2017-12-11" AND pdf_url is NULL')->get();

使用 whereNull

$shipment_data = DB::table('shipment')
->whereNull('pdf_url')->get();

试试这个:

$records = DB::table('shipment')
->where('shipment_date','2017-12-11')
->whereNull('pdf_url')
->get();

您可以使用 whereNull

The whereNull method verifies that the value of the given column is NULL.

https://laravel.com/docs/5.5/queries

最新更新