Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions resources/views/components/users/⚡info-cards.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public function render()
{
$user = User::find($this->userId)->loadCount([
'posts',
'posts as posts_count_in_this_year' => function ($query) {
$query->whereYear('created_at', date('Y'));
},
Expand All @@ -24,11 +25,12 @@ public function render()
->where('posts.user_id', $user->id)
->count();

$categories = Category::with([
'posts' => function ($query) use ($user) {
$query->where('user_id', $user->id);
},
])->get();
$categories = Category::query()
->withCount([
'posts' => function ($query) use ($user) {
$query->where('user_id', $user->id);
},
])->get();

return $this->view([
'user' => $user,
Expand Down Expand Up @@ -129,8 +131,8 @@ class="rounded-full size-36"
</div>
<div class="flex col-span-11 items-center">
@php
$barWidth = $category->posts->count()
? (int) (($category->posts->count() / $user->posts->count()) * 100)
$barWidth = $category->posts_count
? (int) (($category->posts_count / $user->posts_count) * 100)
: 0.2;
@endphp

Expand All @@ -144,7 +146,7 @@ class="h-4 from-green-500 via-emerald-500 to-teal-500 transition-all duration-30

<div
class="flex col-span-1 justify-end items-center text-lg font-semibold text-teal-500 dark:text-purple-500">
{{ $category->posts->count() }}
{{ $category->posts_count }}
</div>
@endforeach
</div>
Expand All @@ -153,7 +155,7 @@ class="flex col-span-1 justify-end items-center text-lg font-semibold text-teal-
<x-card class="flex flex-col col-span-6 justify-between items-start md:col-span-2 dark:text-zinc-50">
<div class="w-full text-2xl text-left">文章總數</div>
<div class="w-full text-8xl font-semibold text-center text-teal-500 dark:text-purple-500 count-up">
{{ $user->posts->count() }}</div>
{{ $user->posts_count }}</div>
<div class="w-full text-2xl text-right">篇</div>
</x-card>

Expand Down
Loading