hasMany(ProductTranslate::class); } public function services() { return $this->hasMany(Service::class); } public function getCategoryAttribute() { return $this->prod_plugin_file; } public function getDescriptionAttribute() { // @todo If the user has selected a specific language. return $this->description($this->getDefaultLanguage()); } public function getNameAttribute() { return $this->name(Auth::user()->language); } public function getProductIdAttribute() { return sprintf('#%04s',$this->id); } public function scopeActive() { return $this->where('active',TRUE); } public function description(Language $lo=NULL) { if (is_null($lo)) $lo = $this->getDefaultLanguage(); return $this->descriptions->where('language_id',$lo->id)->first()->description_short; } private function getDefaultLanguage() { return config('SITE_SETUP')->language; } /** * Get the product name * * @param Language $lo * @return string Product Name */ public function name(Language $lo=NULL) { if (is_null($lo)) $lo = $this->getDefaultLanguage(); return $this->descriptions->where('language_id',$lo->id)->first()->name; } }