mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
This change removes the `latestSptVersion()` relationship, which fetched the latest mod version for the latest SPT version, with a more simple `latestVersion()` relationship that simply fetches the latest mod version based on the mod version, version number field. This is less complicated and much less confusing.
100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components;
|
|
|
|
use App\Models\Mod;
|
|
use App\Models\ModVersion;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\View\Component;
|
|
|
|
class ModListSection extends Component
|
|
{
|
|
public Collection $modsFeatured;
|
|
|
|
public Collection $modsLatest;
|
|
|
|
public Collection $modsUpdated;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->modsFeatured = $this->fetchFeaturedMods();
|
|
$this->modsLatest = $this->fetchLatestMods();
|
|
$this->modsUpdated = $this->fetchUpdatedMods();
|
|
}
|
|
|
|
private function fetchFeaturedMods(): Collection
|
|
{
|
|
return Cache::remember('homepage-featured-mods', now()->addMinutes(5), function () {
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
->withTotalDownloads()
|
|
->with(['latestVersion', 'latestVersion.sptVersion', 'users:id,name'])
|
|
->whereHas('latestVersion')
|
|
->where('featured', true)
|
|
->latest()
|
|
->limit(6)
|
|
->get();
|
|
});
|
|
}
|
|
|
|
private function fetchLatestMods(): Collection
|
|
{
|
|
return Cache::remember('homepage-latest-mods', now()->addMinutes(5), function () {
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at'])
|
|
->withTotalDownloads()
|
|
->with(['latestVersion', 'latestVersion.sptVersion', 'users:id,name'])
|
|
->whereHas('latestVersion')
|
|
->latest()
|
|
->limit(6)
|
|
->get();
|
|
});
|
|
}
|
|
|
|
private function fetchUpdatedMods(): Collection
|
|
{
|
|
return Cache::remember('homepage-updated-mods', now()->addMinutes(5), function () {
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
->withTotalDownloads()
|
|
->with(['lastUpdatedVersion', 'lastUpdatedVersion.sptVersion', 'users:id,name'])
|
|
->whereHas('lastUpdatedVersion')
|
|
->orderByDesc(
|
|
ModVersion::select('updated_at')
|
|
->whereColumn('mod_id', 'mods.id')
|
|
->orderByDesc('updated_at')
|
|
->take(1)
|
|
)
|
|
->limit(6)
|
|
->get();
|
|
});
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('components.mod-list-section', [
|
|
'sections' => $this->getSections(),
|
|
]);
|
|
}
|
|
|
|
public function getSections(): array
|
|
{
|
|
return [
|
|
[
|
|
'title' => 'Featured Mods',
|
|
'mods' => $this->modsFeatured,
|
|
'versionScope' => 'latestVersion',
|
|
],
|
|
[
|
|
'title' => 'Newest Mods',
|
|
'mods' => $this->modsLatest,
|
|
'versionScope' => 'latestVersion',
|
|
],
|
|
[
|
|
'title' => 'Recently Updated Mods',
|
|
'mods' => $this->modsUpdated,
|
|
'versionScope' => 'lastUpdatedVersion',
|
|
],
|
|
];
|
|
}
|
|
}
|