Add streaks and milestone badges
No gamification existed at all - nothing rewarded consistency or gave users a reason to come back beyond the raw session stats already on the dashboard. Adds a Gamification helper that derives (not stores) a current/longest daily streak from completed WorkoutSessions and six badges (first session, 10 and 50 sessions, 7- and 30-day streaks, a 100kg+ completed lift) from existing session/session-item data - no new tables, since everything needed is already recorded. Found and fixed a real Carbon 3 behavior change via testing: diffInDays() no longer returns an absolute value by default (unlike Carbon 2) - it returns a signed float. My longest-streak calculation used a strict === 1 check against the raw result, which silently always failed because float(-1) or float(1) never strictly equals int 1. Fixed with abs() plus an explicit (int) cast. Worth remembering for any other diffIn*() usage in this codebase going forward. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\WorkoutSession;
|
||||
use App\Support\Gamification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@@ -55,6 +56,9 @@ class DashboardController extends Controller
|
||||
? round($weightLogs->last()->weight_kg - $weightLogs->first()->weight_kg, 2)
|
||||
: null;
|
||||
|
||||
// Streaks and badges
|
||||
$gamification = Gamification::forUser($user);
|
||||
|
||||
return view('dashboard', compact(
|
||||
'workoutsCount',
|
||||
'sessionsCount',
|
||||
@@ -63,7 +67,8 @@ class DashboardController extends Controller
|
||||
'recentSessions',
|
||||
'dailyActivity',
|
||||
'weightLogs',
|
||||
'weightChange'
|
||||
'weightChange',
|
||||
'gamification'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user