Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel eloquent model query for `not null`

I've been using Laravel for a project and using the Eloquent models to grab the model instances I need.

However, it doesn't look like there's a way to query for not null values.

https://laravel.com/docs/5.4/eloquent#retrieving-models

Is there a way to do something like this, where I want to get all Flight models where the ticket_id is not null?

$flight = App\Flight::where('ticket_id', '!=', null);
like image 388
user101289 Avatar asked Nov 28 '22 13:11

user101289


1 Answers

Try this

$flight = App\Flight::whereNotNull('ticket_id')->get();
like image 135
A.khalifa Avatar answered Dec 04 '22 04:12

A.khalifa