Larave Extracting Two Dates Out of One
Extracting two dates out of one, like in the case of startOfMonth & endOfMonth, make sure not to apply both functions on the same date variable. Otherwise, you get unexpected results. ๐
class GetUserTokesConsuemed
{
public function execute(User $user, Carbon $date = null):mixed
{
$date = $date ?? Carbon::now();
// โ don't do
$startDate = $date->startOfMonth();
$endDate = $date->endOfMonth();
// โ๏ธ do
$startDate = $date->startOfMonth();
$endDate = $date->copy()->endOfMonth(); // make a copy
// ...
}
}