Add tips count to leaderboard

Also rename memes_total to memes_count to make it more consistent
This commit is contained in:
dev 2021-08-10 21:55:34 -07:00
parent bb8ee230a6
commit 4c1b493943
4 changed files with 12 additions and 5 deletions

View File

@ -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;
});

View File

@ -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');

View File

@ -11,6 +11,7 @@
<tr>
<th scope="col">User</th>
<th scope="col">Meme Count</th>
<th scope="col">Tips Count</th>
<th scope="col">Total XMR Tips</th>
</tr>
</thead>
@ -18,7 +19,8 @@
@foreach ($data['users'] as $user)
<tr>
<td><a href="{{ url('/user/' . $user->id) }}">{{ $user->name }}</a></td>
<td>{{ $user->memes_total }}</td>
<td>{{ $user->memes_count }}</td>
<td>{{ $user->tips_count }}</td>
<td>{{ $user->tips_total }}</td>
</tr>
@endforeach

View File

@ -6,7 +6,7 @@
<div class="col-md-12">
<h3 class="text-center mb-3">Memes By {{ $data['user']->name }}</h3>
<p class="text-center">Total Earnings: {{ $data['user']->tips_total }}</h3>
<p class="text-center">Total Memes: {{ $data['user']->memes_total }}</h3>
<p class="text-center">Total Memes: {{ $data['user']->memes_count }}</h3>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-4 grid-memes">
@foreach ($data['memes'] as $meme)
<div class="col mb-4">