where(function ($q) use ($search) { $q->orWhere('name', 'LIKE', $search) ->orWhere('type', 'LIKE', $search) ->orWhere('values', 'LIKE', $search) ->orWhere('status', 'LIKE', $search); }); } public function user() { return $this->belongsTo(User::class); } public function values() { return $this->hasMany(VerificationFieldValue::class); } public function verification_field_values() { return $this->hasMany(VerificationFieldValue::class, 'verification_field_id'); } public function translations() { return $this->hasMany(VerificationFieldsTranslation::class, 'verification_field_id'); } public function getTranslatedNameAttribute() { $languageCode = request()->header('Content-Language') ?? app()->getLocale(); // Find the language record $language = Language::where('code', $languageCode)->first(); // If translations relationship is not loaded, load it if (!$this->relationLoaded('translations')) { $this->load('translations'); } if ($language) { $translation = $this->translations->first(function ($data) use ($language) { return $data->language_id == $language->id; }); return $translation->name ?? null; // return null if translation is missing } return null; // No language found } public function getTranslatedValueAttribute() { $languageCode = request()->header('Content-Language') ?? app()->getLocale(); if ($this->relationLoaded('translations')) { $language = Language::where('code', $languageCode)->first(); if ($language) { $translation = $this->translations->first(fn($t) => $t->language_id == $language->id); return $translation && !empty($translation->value) ? $translation->value : $this->values; } } return $this->values; } }