Brand.php 548 B

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