A
A
Alexander Koregin2020-08-26 13:12:20
Laravel
Alexander Koregin, 2020-08-26 13:12:20

How to validate date in laravel?

I need to display posts that do not have a deadline, but it may be that the post does not have a deadline and it also needs to be displayed. I myself wrote this, I have an error.

->whereHas('unpublished_at', function ($query) {
   return substr(date('Y-m-d', strtotime($query.'1 day')),0,10) < date('Y-m-d');
})


Logically, it should be like this deadline +1 < today

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2020-08-26
@dragonika8

https://laravel.com/docs/7.x/queries#where-clauses

A
Anton R., 2020-08-26
@anton_reut

How can you mathematically compare strings through < ?
Your date('Ymd') output is a string, not a number. Convert time to Unix and then compare numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question