diff --git "a/resources/views/components/users/\342\232\241info-cards.blade.php" "b/resources/views/components/users/\342\232\241info-cards.blade.php" index da2b8a54..27a21fe8 100644 --- "a/resources/views/components/users/\342\232\241info-cards.blade.php" +++ "b/resources/views/components/users/\342\232\241info-cards.blade.php" @@ -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')); }, @@ -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, @@ -129,8 +131,8 @@ class="rounded-full size-36"
@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 @@ -144,7 +146,7 @@ class="h-4 from-green-500 via-emerald-500 to-teal-500 transition-all duration-30
- {{ $category->posts->count() }} + {{ $category->posts_count }}
@endforeach
@@ -153,7 +155,7 @@ class="flex col-span-1 justify-end items-center text-lg font-semibold text-teal-
文章總數
- {{ $user->posts->count() }}
+ {{ $user->posts_count }}