I want to get daily data from my database. I try 2 code and both are not working for me.
$sales=Sale::whereDate('created_at', '=', Carbon::today());
The error that I got:
Class ‘AppHttpControllersCarbon’ not found
and when I try
$sales=Sale::whereDay('created_at', now()->day)->get();
The error that I got:
Call to undefined function AppHttpControllersnow()
3
Answers
put
use CarbonCarbon;
at top afternamespace
then use this code.You should try to import Carbon and then use it:
Then inside your code you can use Carbon like:
here in laravel created_at returns a value with Y-m-d & time & minute with all of this information
$now=Carbon::now();
here how returns the value with Y-m-d & time & minute with all of this information.&it changing every second.
Now here if you want to get your query then need to format your getting now or today.try this,