⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
b2c-booking.dev-unit.com
/
app
/
Traits
/
View File Name :
HasTranslations.php
<?php /** * Created by PhpStorm. * User: dunglinh * Date: 6/8/19 * Time: 22:06 */ namespace App\Traits; trait HasTranslations { /** * Class name for translation, default is current class * @var */ protected $translation_class; /** * @param false $locale * @return boolean */ public function saveTranslation($locale = false,$saveSEO = false){ if(is_enable_multi_lang()){ $translation = $this->translate($locale); $translation->fillByAttr($translation->fillable, request()->input()); $translation->save(); if($saveSEO){ $translation->saveSEO(request(),$locale); } } return true; } /** * Get Translated Model * * @param false $locale * @return $this */ public function translate($locale = false){ if(!is_enable_multi_lang()){ return $this; } if(empty($locale)) $locale = app()->getLocale(); $class = $this->getTranslationModelName(); if($locale == app()->getLocale()){ $find = $this->translation; }else { $find = $class::query()->where([ 'origin_id' => $this->getKey(), 'locale' => $locale, ])->first(); } if(!$find){ $find = app()->make($class); $find->locale = $locale; $find->origin_id = $this->getKey(); // Cant use fill() here cuz it wont work with cast keys foreach ($find->fillable as $key){ $find->setAttribute($key,$this->getAttribute($key)); } } return $find; } /** * @internal will change to private */ public function getTranslationModelName(): string { $class = $this->translation_class; if(!$class and class_exists(get_class($this).'Translation')){ $class = get_class($this).'Translation'; } return $class; } public function translation(){ return $this->hasOne($this->getTranslationModelName(),'origin_id')->where('locale',app()->getLocale()); } /** * @todo Save Translation or Origin Language * @param bool $locale * @param bool $saveSeo * @return bool|null */ public function saveOriginOrTranslation($locale = false,$saveSeo = true) { if(!$locale) $locale = get_main_lang(); if(is_default_lang($locale)){ // Main lang, we need to save origin table also $this->save(); } if($saveSeo){ $this->saveSEO(request(),is_default_lang($locale) ? null : $locale ); } $res = $this->saveTranslation($locale,$saveSeo); return $res; } }