forge/app/View/Components/ModListSection.php

68 lines
1.7 KiB
PHP
Raw Normal View History

2024-05-17 23:54:03 -04:00
<?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
{
2024-05-21 21:02:49 -04:00
public Collection $modsFeatured;
2024-05-22 01:00:37 -04:00
2024-05-17 23:54:03 -04:00
public Collection $modsLatest;
2024-05-22 01:00:37 -04:00
2024-05-17 23:54:03 -04:00
public Collection $modsUpdated;
public function __construct()
{
2024-05-21 21:02:49 -04:00
$this->modsFeatured = $this->fetchFeaturedMods();
2024-05-17 23:54:03 -04:00
$this->modsLatest = $this->fetchLatestMods();
$this->modsUpdated = $this->fetchUpdatedMods();
}
2024-05-21 21:02:49 -04:00
private function fetchFeaturedMods(): Collection
2024-05-17 23:54:03 -04:00
{
2024-05-21 21:02:49 -04:00
return Mod::with('versionLatestSptVersion.sptVersion')->whereFeatured(true)->take(6)->get();
2024-05-17 23:54:03 -04:00
}
private function fetchLatestMods(): Collection
{
return Mod::with('versionLatestSptVersion.sptVersion')->latest()->take(6)->get();
}
private function fetchUpdatedMods(): Collection
{
return Mod::with('versionLastUpdated.sptVersion')->take(6)->get();
}
public function getSections(): array
{
return [
[
2024-05-21 21:02:49 -04:00
'title' => 'Featured Mods',
'mods' => $this->modsFeatured,
2024-05-22 01:00:37 -04:00
'versionScope' => 'versionLatestSptVersion',
2024-05-17 23:54:03 -04:00
],
[
'title' => 'Latest Mods',
'mods' => $this->modsLatest,
2024-05-22 01:00:37 -04:00
'versionScope' => 'versionLatestSptVersion',
2024-05-17 23:54:03 -04:00
],
[
'title' => 'Recently Updated Mods',
'mods' => $this->modsUpdated,
2024-05-22 01:00:37 -04:00
'versionScope' => 'versionLastUpdated',
2024-05-17 23:54:03 -04:00
],
];
}
public function render(): View
{
return view('components.mod-list-section', [
'sections' => $this->getSections(),
]);
}
}