when($ignoreId, fn($q) => $q->where('id', '!=', $ignoreId)) ->exists() && $i < 100 ){ $slug = $baseSlug . '-' . $i++; } if( $i >= 100 ){ $slug = Str::uuid(); // Fallback... } return $slug; } /** * Build complete title. * * @param string $section * @param array $fields * * @return string */ public static function buildCompleteTitle( string $section, array $fields = [] ){ return match ($section) { 'translations' => sprintf('%s (%s Translation) %s', $fields['entry_title'] ?? $fields['game_name'], $fields['languages_string'], $fields['platform_name']), 'romhacks' => sprintf('%s (%s) Romhack', $fields['entry_title'], $fields['platform_name']), 'homebrew' => sprintf('%s (%s) Homebrew', $fields['game_name'], $fields['platform_name']), 'utilities' => sprintf('%s - Utility', $fields['entry_title']), 'documents' => sprintf('%s - Document', $fields['entry_title']), 'lua-scripts' => sprintf('%s (%s) LUA Script', $fields['entry_title'], $fields['platform_name']), 'tutorials' => sprintf('%s - Tutorial', $fields['entry_title']), default => $fields['entry_title'], }; } public static function getLatestComments(Entry $entry, int $limit = 20): array { if( !$entry->comments_thread_id ){ return []; } $cacheKey = "entry_comments_{$entry->id}"; return Cache::remember($cacheKey, now()->addDays(1), function () use ($entry, $limit) { $service = app(XenforoApiService::class); // Get thread infos and pagination. $paginationInfos = $service->getThreadPosts($entry->comments_thread_id, 1); $lastPage = $paginationInfos['pagination']['last_page'] ?? 1; // Get last threads $lastPageData = $lastPage > 1 ? $service->getThreadPosts($entry->comments_thread_id, $lastPage) : $paginationInfos; $posts = $lastPageData['posts'] ?? []; if( count( $posts ) < $limit && $lastPage > 1 ){ $previousPageData = $service->getThreadPosts($entry->comments_thread_id, $lastPage - 1 ); $posts = array_merge( $posts, $previousPageData['posts'] ?? [] ); } return collect( $posts )->slice(-$limit)->reverse()->values()->toArray(); }); } }