Search code examples
phplaravel-5php-carbon

Count the users created within last week in Laravel


How to use carbon and count the users created in the last 7 days. On blade, I have a table that shows the total of users created per day that has this syntax (example is for today)

$getusertoday = MemberProfile::where('encoded_by', '=', $profile->name)
            ->whereDate('created_at', '=', $today )->count();

But in the last column, which is the Weekly Total, I must total everything.


Solution

  • $getusertoday = MemberProfile::where('encoded_by', '=', $profile->name)
            ->whereDate('created_at', '>=', date('Y-m-d H:i:s',strtotime('-7 days')) )->count();