Product.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class Product extends Model
  6. {
  7. protected $guarded = ['choice_attributes'];
  8. protected $with = ['product_translations', 'taxes'];
  9. public function getTranslation($field = '', $lang = false)
  10. {
  11. $lang = $lang == false ? App::getLocale() : $lang;
  12. $product_translations = $this->product_translations->where('lang', $lang)->first();
  13. return $product_translations != null ? $product_translations->$field : $this->$field;
  14. }
  15. public function product_translations()
  16. {
  17. return $this->hasMany(ProductTranslation::class);
  18. }
  19. public function category()
  20. {
  21. return $this->belongsTo(Category::class);
  22. }
  23. public function brand()
  24. {
  25. return $this->belongsTo(Brand::class);
  26. }
  27. public function user()
  28. {
  29. return $this->belongsTo(User::class);
  30. }
  31. public function orderDetails()
  32. {
  33. return $this->hasMany(OrderDetail::class);
  34. }
  35. public function reviews()
  36. {
  37. return $this->hasMany(Review::class)->where('status', 1);
  38. }
  39. public function wishlists()
  40. {
  41. return $this->hasMany(Wishlist::class);
  42. }
  43. public function stocks()
  44. {
  45. return $this->hasMany(ProductStock::class);
  46. }
  47. public function taxes()
  48. {
  49. return $this->hasMany(ProductTax::class);
  50. }
  51. public function flash_deal_product()
  52. {
  53. return $this->hasOne(FlashDealProduct::class);
  54. }
  55. public function bids()
  56. {
  57. return $this->hasMany(AuctionProductBid::class);
  58. }
  59. public function scopePhysical($query)
  60. {
  61. return $query->where('digital', 0);
  62. }
  63. public function seller_spread_package_payment()
  64. {
  65. return $this->belongsTo(SellerSpreadPackagePayment::class);
  66. }
  67. }