mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
- Updated the SptVersion and ModVersion dependancies to resolve *all* compatible versions and introduced new relationships to pull just the latest compatible version. Had to rewrite a *bunch*, but it should be much more capable now. It can be expensive to resolve these properties when iterated over, so *make sure they're eager loaded using the `with` method when you're building the queries*. - Updated the mod listing Livewire component to save the filter options within the PHP session instead of in browser local storage. *Much* cleaner. - Removed caching from homepage queries to see how they preform on production. Will add back later. - Updated ModVersion factory to create SptVersions if there are none specified. - Probably lots of other changes too... I need to make smaller commits. :(
105 lines
2.9 KiB
PHP
105 lines
2.9 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\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 Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
->withTotalDownloads()
|
|
->with([
|
|
'latestVersion',
|
|
'latestVersion.latestSptVersion:id,version,color_class',
|
|
'users:id,name',
|
|
'license:id,name,link',
|
|
])
|
|
->where('featured', true)
|
|
->latest()
|
|
->limit(6)
|
|
->get();
|
|
}
|
|
|
|
private function fetchLatestMods(): Collection
|
|
{
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at'])
|
|
->withTotalDownloads()
|
|
->with([
|
|
'latestVersion',
|
|
'latestVersion.latestSptVersion:id,version,color_class',
|
|
'users:id,name',
|
|
'license:id,name,link',
|
|
])
|
|
->latest()
|
|
->limit(6)
|
|
->get();
|
|
}
|
|
|
|
private function fetchUpdatedMods(): Collection
|
|
{
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
->withTotalDownloads()
|
|
->with([
|
|
'latestVersion',
|
|
'latestVersion.latestSptVersion:id,version,color_class',
|
|
'users:id,name',
|
|
'license:id,name,link',
|
|
])
|
|
->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',
|
|
],
|
|
];
|
|
}
|
|
}
|