From 1dc72d8563205c2ce677e1e4e8d2f2362a4fdc1b Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Tue, 23 Jun 2026 18:10:22 +0330
Subject: [PATCH] 1.3: fix N+1 in getTranslation by using eager-loaded
collection
---
app/Models/Website/AboutMe.php | 3 +++
app/Models/Website/Service.php | 3 +++
app/Models/Website/Skill.php | 3 +++
3 files changed, 9 insertions(+)
diff --git a/app/Models/Website/AboutMe.php b/app/Models/Website/AboutMe.php
index 111410a..4f4fac7 100644
--- a/app/Models/Website/AboutMe.php
+++ b/app/Models/Website/AboutMe.php
@@ -25,6 +25,9 @@ public function translations()
*/
public function getTranslation($locale)
{
+ if ($this->relationLoaded('translations')) {
+ return $this->translations->firstWhere('locale', $locale);
+ }
return $this->translations()->where('locale', $locale)->first();
}
diff --git a/app/Models/Website/Service.php b/app/Models/Website/Service.php
index a638baa..9f8193b 100644
--- a/app/Models/Website/Service.php
+++ b/app/Models/Website/Service.php
@@ -25,6 +25,9 @@ public function translations()
*/
public function getTranslation($locale)
{
+ if ($this->relationLoaded('translations')) {
+ return $this->translations->firstWhere('locale', $locale);
+ }
return $this->translations()->where('locale', $locale)->first();
}
diff --git a/app/Models/Website/Skill.php b/app/Models/Website/Skill.php
index e3494d0..2caa13d 100644
--- a/app/Models/Website/Skill.php
+++ b/app/Models/Website/Skill.php
@@ -33,6 +33,9 @@ public function translations()
*/
public function getTranslation($locale)
{
+ if ($this->relationLoaded('translations')) {
+ return $this->translations->firstWhere('locale', $locale);
+ }
return $this->translations()->where('locale', $locale)->first();
}