forge/app/View/Components/ModListSection.php
Refringe 4cb739f50c
More Updates
- Updates dependancies
- Added time to mod component
- Implement naturalSort function into homepage queries

Short todo:
- Migrate top navigation from old-build
- Mod detail page
2024-05-28 17:19:36 -04:00

87 lines
2.3 KiB
PHP

<?php
namespace App\View\Components;
use App\Models\Mod;
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', 'user_id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
->withLatestSptVersion()
->withTotalDownloads()
->with('user:id,name')
->where('featured', true)
->latest()
->limit(6)
->get();
}
private function fetchLatestMods(): Collection
{
return Mod::select(['id', 'user_id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at'])
->withLatestSptVersion()
->withTotalDownloads()
->with('user:id,name')
->latest()
->limit(6)
->get();
}
private function fetchUpdatedMods(): Collection
{
return Mod::select(['id', 'user_id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
->withLastUpdatedVersion()
->withTotalDownloads()
->with('user:id,name')
->latest()
->limit(6)
->get();
}
public function getSections(): array
{
return [
[
'title' => 'Featured Mods',
'mods' => $this->modsFeatured,
'versionScope' => 'latestSptVersion',
],
[
'title' => 'Newest Mods',
'mods' => $this->modsLatest,
'versionScope' => 'latestSptVersion',
],
[
'title' => 'Recently Updated Mods',
'mods' => $this->modsUpdated,
'versionScope' => 'lastUpdatedVersion',
],
];
}
public function render(): View
{
return view('components.mod-list-section', [
'sections' => $this->getSections(),
]);
}
}