php Laravel eloquent 模型查询`not null`
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44599594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel eloquent model query for `not null`
提问by user101289
I've been using Laravel for a project and using the Eloquent models to grab the model instances I need.
我一直在为一个项目使用 Laravel,并使用 Eloquent 模型来获取我需要的模型实例。
However, it doesn't look like there's a way to query for not nullvalues.
但是,似乎没有一种方法可以查询not null值。
https://laravel.com/docs/5.4/eloquent#retrieving-models
https://laravel.com/docs/5.4/eloquent#retrieving-models
Is there a way to do something like this, where I want to get all Flightmodels where the ticket_idis not null?
有没有办法做这样的事情,在这里我想获得的所有Flight车型,其中ticket_id是not null?
$flight = App\Flight::where('ticket_id', '!=', null);
回答by A.khalifa
Try this
尝试这个
$flight = App\Flight::whereNotNull('ticket_id')->get();

