diff --git a/app/Http/Controllers/ModController.php b/app/Http/Controllers/ModController.php
index 1a26bdcc..668a67eb 100644
--- a/app/Http/Controllers/ModController.php
+++ b/app/Http/Controllers/ModController.php
@@ -30,14 +30,7 @@ public function getIndex(): RedirectResponse
public function getList(): View
{
- $mods = Mod::with(
- [
- 'versions' => function ($query) {
- $query->orderBy('modversions.updated_at', 'desc');
- },
- ]
- )
- ->get();
+ $mods = Mod::with('latestVersion')->get();
return view('mod.list')->with(['mods' => $mods]);
}
diff --git a/app/Models/Mod.php b/app/Models/Mod.php
index 7251b7fd..d3e5b1f8 100644
--- a/app/Models/Mod.php
+++ b/app/Models/Mod.php
@@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
+use Illuminate\Database\Eloquent\Relations\HasOne;
class Mod extends Model
{
@@ -13,4 +14,9 @@ public function versions(): HasMany
{
return $this->hasMany(Modversion::class);
}
+
+ public function latestVersion(): HasOne
+ {
+ return $this->hasOne(Modversion::class)->latestOfMany('updated_at');
+ }
}
diff --git a/resources/views/mod/list.blade.php b/resources/views/mod/list.blade.php
index 5a33c1a7..3a46d2fa 100644
--- a/resources/views/mod/list.blade.php
+++ b/resources/views/mod/list.blade.php
@@ -47,7 +47,7 @@
@endif
Latest
- Version: {{ !$mod->versions->isEmpty() ? $mod->versions->first()->version : "N/A" }}
+ Version: {{ $mod->latestVersion ? $mod->latestVersion->version : "N/A" }}