CustomerProduct.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class CustomerProduct extends Model
  6. {
  7. protected $with = ['customer_product_translations'];
  8. public function getTranslation($field = '', $lang = false){
  9. $lang = $lang == false ? App::getLocale() : $lang;
  10. $customer_product_translations = $this->customer_product_translations->where('lang', $lang)->first();
  11. return $customer_product_translations != null ? $customer_product_translations->$field : $this->$field;
  12. }
  13. public function category(){
  14. return $this->belongsTo(Category::class);
  15. }
  16. public function subcategory(){
  17. return $this->belongsTo(SubCategory::class);
  18. }
  19. public function subsubcategory(){
  20. return $this->belongsTo(SubSubCategory::class);
  21. }
  22. public function brand(){
  23. return $this->belongsTo(Brand::class);
  24. }
  25. public function user(){
  26. return $this->belongsTo(User::class);
  27. }
  28. public function state(){
  29. return $this->belongsTo(State::class);
  30. }
  31. public function city(){
  32. return $this->belongsTo(City::class);
  33. }
  34. public function customer_product_translations(){
  35. return $this->hasMany(CustomerProductTranslation::class);
  36. }
  37. }