K
K
KyIIpyM2016-05-21 16:24:58
Laravel
KyIIpyM, 2016-05-21 16:24:58

Why does fetching from the database by date not work in laravel5?

There is a structure like this:

$posts = Post::latest('published_at')->where('published_at', '<=', Carbon::now())->get();

Logically, if the publication day is worth less than today or today, then the post is displayed. However, in reality, only those posts are displayed for which the date is one day less than today.
If you write '>=' then everything works out correctly (both today's and future posts are displayed).
Tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KyIIpyM, 2016-05-21
@KyIIpyM

The problem was in time zones, the provider has Kievskaya, and in the city of Moscow. Registered Carbon::now('Europe/Moscow')
and everything worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question