Attribute.php 693 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class Attribute extends Model
  6. {
  7. protected $with = ['attribute_translations'];
  8. public function getTranslation($field = '', $lang = false){
  9. $lang = $lang == false ? App::getLocale() : $lang;
  10. $attribute_translation = $this->attribute_translations->where('lang', $lang)->first();
  11. return $attribute_translation != null ? $attribute_translation->$field : $this->$field;
  12. }
  13. public function attribute_translations(){
  14. return $this->hasMany(AttributeTranslation::class);
  15. }
  16. public function attribute_values() {
  17. return $this->hasMany(AttributeValue::class);
  18. }
  19. }