public function index($userId = null) { $auth = auth(); if (!$userId) { $userId = $auth->id(); $isAuthUser = true; } else { $isAuthUser = $userId == $auth->id(); } if ($isAuthUser) { $user = $auth->user(); } else { $user = User::findOrFail($userId); } $count['create'] = Project::where('user_id', $userId)->count(); $count['join'] = Project::join('project_members', function ($join) use($userId) { $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId); })->where('projects.user_id', '<>', $userId)->count(); $count['comment'] = 0; $count['collect'] = ProjectFavorite::where('user_id', $userId)->count(); $showList = 'create'; foreach ($count as $key => $value) { if ($value > 0) { $showList = $key; break; } } return view('user.home.index', ['userData' => $user, 'isAuthUser' => $isAuthUser, 'projectCount' => $count, 'showList' => $showList]); }