Laravel Query Builder - where the date now uses carbon

How to get only the date in the database column, I am having difficulty using Carbon on the controller:

$data['nowUser'] = User::where('date', Carbon::today()->toDateString())->get();

In the Date column, it looks like this:

enter image description here

+4
source share
1 answer

This is a column DATETIME, so there is no need for additional formatting of the instance Carbon. However, you need to use whereDateit if you want to fetch all users for which the column datecontains today's date:

$data['nowUser'] = User::whereDate('date', '=', Carbon::today())->get();

Carbon::today() Query Builder __toString DATETIME string Carbon::DEFAULT_TO_STRING_FORMAT, MySQL Y-m-d H:i:s.

+7

Source: https://habr.com/ru/post/1619672/


All Articles