diff --git a/app/Http/Controllers/MemeController.php b/app/Http/Controllers/MemeController.php index 3e02dd7..8f0b09b 100644 --- a/app/Http/Controllers/MemeController.php +++ b/app/Http/Controllers/MemeController.php @@ -40,7 +40,7 @@ class MemeController extends Controller public function leaderboard() { SEOTools::setTitle('Leaderboard'); - $users = User::with('tips')->has('memes')->get(); + $users = User::with('tips')->withCount('tips')->has('memes')->get(); $users = $users->sortByDesc(function($user) { return $user->tips_total; }); diff --git a/app/Models/User.php b/app/Models/User.php index 577235f..a9148ef 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,7 +11,7 @@ class User extends Authenticatable { use HasFactory, Notifiable; - protected $appends = ['tips_total', 'memes_total']; + protected $appends = ['tips_count', 'tips_total', 'memes_count']; /** * The attributes that are mass assignable. @@ -54,11 +54,16 @@ class User extends Authenticatable return $this->hasManyThrough(Tip::class, Meme::class, 'user_id'); } - public function getMemesTotalAttribute() + public function getMemesCountAttribute() { return $this->memes->count(); } + public function getTipsCountAttribute() + { + return $this->tips->where('is_deposit', 1)->count(); + } + public function getTipsTotalAttribute() { return $this->tips->where('is_deposit', 1)->sum('amount_formatted'); diff --git a/resources/views/leaderboard.blade.php b/resources/views/leaderboard.blade.php index f9e29ce..fecdd5f 100644 --- a/resources/views/leaderboard.blade.php +++ b/resources/views/leaderboard.blade.php @@ -11,6 +11,7 @@
Total Earnings: {{ $data['user']->tips_total }} -
Total Memes: {{ $data['user']->memes_total }} +
Total Memes: {{ $data['user']->memes_count }}