Demers94
3 months ago

where() clause only when value is not NULL

Posted 3 months ago by Demers94

Some models in my application have a ends_at column that can be null

I would like to fetch all the models that have a ends_at value greater than the current date, or that have NULL set as the value

Here is my current query :

$models = Model::where('ends_at', '>=', Carbon::now())->get();

However, this will only return models that have the ends_at field set. How can I include the NULL ones as well?

Thanks for the help!

Please sign in or create an account to participate in this conversation.