diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 9657002..5226771 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -39,7 +39,21 @@ SQL ->with('tags') ->paginate(20); - return view('user.profile')->with(compact('user', 'ejaculations')); + // よく使っているタグ + $tagsQuery = DB::table('ejaculations') + ->join('ejaculation_tag', 'ejaculations.id', '=', 'ejaculation_tag.ejaculation_id') + ->join('tags', 'ejaculation_tag.tag_id', '=', 'tags.id') + ->selectRaw('tags.name, count(*) as count') + ->where('ejaculations.user_id', $user->id); + if (!Auth::check() || $user->id !== Auth::id()) { + $tagsQuery = $tagsQuery->where('ejaculations.is_private', false); + } + $tags = $tagsQuery->groupBy('tags.name') + ->orderBy('count', 'desc') + ->limit(10) + ->get(); + + return view('user.profile')->with(compact('user', 'ejaculations', 'tags')); } public function stats($name) diff --git a/resources/views/user/base.blade.php b/resources/views/user/base.blade.php index 732a569..0f618f9 100644 --- a/resources/views/user/base.blade.php +++ b/resources/views/user/base.blade.php @@ -6,6 +6,8 @@
@component('components.profile', ['user' => $user]) @endcomponent + @section('sidebar') + @show