芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/yeahea.digitalhubbd.com/app/Models/Attribute.php
with(['translations' => function ($query) { $query->where('lang', app()->getLocale())->whereNotNull('translation'); }]); }); } /** * Get the Shop associated with the attribute. */ public function shop() { return $this->belongsTo(Shop::class); } /** * Get the AttributeType for the Attribute. */ public function attributeType() { return $this->belongsTo(AttributeType::class); } /** * Attribute has many AttributeValue */ public function attributeValues() { return $this->hasMany(AttributeValue::class)->orderBy('order', 'asc'); } /** * Get the translations for the Attribute. */ public function translations() { return $this->hasMany(AttributeTranslation::class); } /** * Get the inventories for the Attribute. */ public function inventories() { return $this->belongsToMany(Inventory::class, 'attribute_inventory') ->withPivot('attribute_value_id') ->withTimestamps(); } /** * Get the categories for the attributes. */ public function categories(): BelongsToMany { return $this->belongsToMany(Category::class, 'attribute_categories')->withTimestamps(); } /** * Scope a query to only include records from the users shop. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeMine($query) { return $query->where('shop_id', Auth::user()->merchantId()); } /** * Get translated name of the attribute */ public function getNameAttribute($value) { return $this->translateAttribute('name') ?? $value; } /** * Return extra classes to views based on type * * @return string */ public function getCssClassesAttribute() { switch ($this->attribute_type_id) { case static::TYPE_COLOR: return 'color-options'; case static::TYPE_RADIO: return 'radioSelect'; case static::TYPE_SELECT: return 'selectBoxIt'; default: return 'selectBoxIt'; } } /** * Check if the Attribute has a translation for the specified language. * * @param string|null $lang The language code to check for translation. * * @return bool */ public function hasTranslation($lang = null) { $lang = $lang ?? app()->getLocale(); // Use application locale as default. if (!array_key_exists($lang, $this->translationExists)) { $this->translationExists[$lang] = $this->translations()->where('lang', $lang)->exists(); } return $this->translationExists[$lang]; } /** * Translate given attributes value from translation_categories table. * * @param string $attribute - attribute name to translate * * @return string - translated value of the attribute */ public function translateAttribute(string $attribute) { if (Route::currentRouteName() == 'admin.attributes.index') { return null; } $translated_attribute = $this->translations->first(); if (!$translated_attribute || !isset($translated_attribute->translation[$attribute])) { return null; } return $translated_attribute->translation[$attribute]; } }