Reputation: 588
We have an Article Table, has articles. The article has publish_date and expire_date, which are nullable.
Article Table
$table->date('publish_period_from')->nullable();
$table->date('publish_period_to')->nullbale();
We want to retrieve articles, which are on published at that time. This is our query.
$query->where('publish_period_from', '<=' today())
->where('publish_period_to', '>=' today())
but in this case, if an article's date is "null", we can't retrieve the article data.
Do you know how to retrieve it?
converting the columns from nullable() to required is better??
we are using laravel5.5
Upvotes: 0
Views: 62
Reputation: 3040
Something like this should work fine:
$query->where(function ($query) {
$query->where('publish_period_from', '<=' today())
->where('publish_period_to', '>=' today())
})->orWhere(function ($query) {
$query->whereNull('publish_period_from')
->whereNull('publish_period_to');
})->get();
That will return the results where it is published within that time constraint, or where both values are null.
Upvotes: 1