user(); $perPage = 30; // People that $user follows (follower_id = $user) $following = DB::table('user_followers as uf') ->join('users as u', 'u.id', '=', 'uf.user_id') ->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id') ->leftJoin('user_statistics as us', 'us.user_id', '=', 'u.id') ->where('uf.follower_id', $user->id) ->whereNull('u.deleted_at') ->orderByDesc('uf.created_at') ->select([ 'u.id', 'u.username', 'u.name', 'up.avatar_hash', 'us.uploads_count', 'us.followers_count', 'uf.created_at as followed_at', ]) ->paginate($perPage) ->withQueryString() ->through(fn ($row) => (object) [ 'id' => $row->id, 'username' => $row->username, 'name' => $row->name, 'uname' => $row->username ?? $row->name, 'avatar_url' => AvatarUrl::forUser((int) $row->id, $row->avatar_hash, 64), 'profile_url' => '/@' . strtolower((string) ($row->username ?? $row->id)), 'uploads' => $row->uploads_count ?? 0, 'followers_count'=> $row->followers_count ?? 0, 'followed_at' => $row->followed_at, ]); return view('dashboard.following', [ 'following' => $following, 'page_title' => 'People I Follow', ]); } }