From 4c1b493943c4c6fa6278837cc98a4f9e0aa1d8b7 Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 10 Aug 2021 21:55:34 -0700 Subject: [PATCH] Add tips count to leaderboard Also rename memes_total to memes_count to make it more consistent --- app/Http/Controllers/MemeController.php | 2 +- app/Models/User.php | 9 +++++++-- resources/views/leaderboard.blade.php | 4 +++- resources/views/profile.blade.php | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) 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 @@ User Meme Count + Tips Count Total XMR Tips @@ -18,7 +19,8 @@ @foreach ($data['users'] as $user) {{ $user->name }} - {{ $user->memes_total }} + {{ $user->memes_count }} + {{ $user->tips_count }} {{ $user->tips_total }} @endforeach diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index 8455de3..ce03f53 100644 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -6,7 +6,7 @@

Memes By {{ $data['user']->name }}

Total Earnings: {{ $data['user']->tips_total }} -

Total Memes: {{ $data['user']->memes_total }} +

Total Memes: {{ $data['user']->memes_count }}

@foreach ($data['memes'] as $meme)