Can't able to use Carbon's yesterday() function like today() function stand alone
Hi there!
Actually I'm a new being for Laravel, In my Laravel 9 project straight away I can able to use carbon date function of "today()" rather I don't get why I couldn't use "yesterday()"
What I have checked with as follows,
dd(today()); // showing today's date
dd(yesterday()); // throws error
If I used like the following code return with yesterday date,
dd(Carbon::today()); // showing today's date
dd(Carbon::yesterday()); // working fine
For learning, I'm in need of know why I can't able to use yesterday() method
because the framework authors didn't think it was useful enough to justify creating a helper.
today() is a convenience helper.
You could create a pull request to suggest adding it, or you could use today()->subDay()
here is the today() function in its entirety
if (! function_exists('today')) {
/**
* Create a new Carbon instance for the current date.
*
* @param \DateTimeZone|string|null $tz
* @return \Illuminate\Support\Carbon
*/
function today($tz = null)
{
return Date::today($tz);
}
}