artworks = $artworks; } public function index(Request $request) { $page_title = 'Skinbase - Photography, Skins & Wallpapers'; $page_meta_description = 'Skinbase legacy home, rendered via Laravel.'; $page_meta_keywords = 'wallpapers, skins, photography, community'; $featuredResult = $this->artworks->getFeaturedArtworks(null, 39); if ($featuredResult instanceof \Illuminate\Pagination\LengthAwarePaginator) { $featured = $featuredResult->getCollection()->first(); } elseif (is_array($featuredResult)) { $featured = $featuredResult[0] ?? null; } elseif ($featuredResult instanceof Collection) { $featured = $featuredResult->first(); } else { $featured = $featuredResult; } $memberFeatured = $featured; $latestUploads = $this->artworks->getLatestArtworks(20); // Forum news (prefer migrated legacy news category id 2876, fallback to slug) try { $forumNews = DB::table('forum_threads as t1') ->leftJoin('users as u', 't1.user_id', '=', 'u.id') ->leftJoin('forum_categories as c', 't1.category_id', '=', 'c.id') ->selectRaw('t1.id as topic_id, t1.title as topic, COALESCE(u.name, ?) as uname, t1.created_at as post_date, t1.content as preview', ['Unknown']) ->whereNull('t1.deleted_at') ->where(function ($query) { $query->where('t1.category_id', 2876) ->orWhereIn('c.slug', ['news', 'forum-news']); }) ->orderByDesc('t1.created_at') ->limit(8) ->get(); } catch (QueryException $e) { Log::warning('Forum threads table missing or DB error when loading forum news', ['exception' => $e->getMessage()]); $forumNews = collect(); } // Our news (latest site news) try { $ourNews = DB::table('news as t1') ->join('news_categories as c', 't1.category_id', '=', 'c.category_id') ->join('users as u', 't1.user_id', '=', 'u.user_id') ->selectRaw('t1.news_id, t1.headline, t1.user_id, t1.picture, t1.preview, u.uname, t1.create_date, t1.views, c.category_name, (SELECT COUNT(*) FROM news_comments WHERE news_id = t1.news_id) AS num_comments') ->orderBy('t1.create_date', 'desc') ->limit(5) ->get(); } catch (QueryException $e) { Log::warning('News table missing or DB error when loading our news', ['exception' => $e->getMessage()]); $ourNews = collect(); } // Latest forum activity (exclude forum news category) try { $latestForumActivity = DB::table('forum_threads as t1') ->leftJoin('forum_categories as c', 't1.category_id', '=', 'c.id') ->leftJoin('forum_posts as p', function ($join) { $join->on('p.thread_id', '=', 't1.id') ->whereNull('p.deleted_at'); }) ->selectRaw('t1.id as topic_id, t1.title as topic, COUNT(p.id) as numPosts') ->whereNull('t1.deleted_at') ->where(function ($query) { $query->where('t1.category_id', '<>', 2876) ->orWhereNull('t1.category_id'); }) ->where(function ($query) { $query->whereNull('c.slug') ->orWhereNotIn('c.slug', ['news', 'forum-news']); }) ->groupBy('t1.id', 't1.title') ->orderByDesc('t1.last_post_at') ->orderByDesc('t1.created_at') ->limit(10) ->get(); } catch (QueryException $e) { Log::warning('Forum threads table missing or DB error when loading latest forum activity', ['exception' => $e->getMessage()]); $latestForumActivity = collect(); } return view('web.home', compact( 'page_title', 'page_meta_description', 'page_meta_keywords', 'featured', 'memberFeatured', 'latestUploads', 'forumNews', 'ourNews', 'latestForumActivity' )); } }