ProductFlat.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Webkul\Product\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Webkul\Product\Contracts\ProductFlat as ProductFlatContract;
  5. class ProductFlat extends Model implements ProductFlatContract
  6. {
  7. /**
  8. * The table associated with the model.
  9. *
  10. * @var string
  11. */
  12. protected $table = 'product_flat';
  13. /**
  14. * The attributes that aren't mass assignable.
  15. *
  16. * @var array
  17. */
  18. protected $guarded = [
  19. 'id',
  20. 'created_at',
  21. 'updated_at',
  22. ];
  23. /**
  24. * Ignorable attributes.
  25. *
  26. * @var array
  27. */
  28. protected $ignorableAttributes = [
  29. 'pivot',
  30. 'parent_id',
  31. 'attribute_family_id',
  32. ];
  33. /**
  34. * Get the product that owns the attribute value.
  35. *
  36. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  37. */
  38. public function product()
  39. {
  40. return $this->belongsTo(ProductProxy::modelClass());
  41. }
  42. /**
  43. * Get the product that owns the product.
  44. *
  45. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  46. */
  47. public function parent()
  48. {
  49. return $this->belongsTo(self::class, 'parent_id');
  50. }
  51. /**
  52. * Get the product variants that owns the product.
  53. *
  54. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  55. */
  56. public function variants()
  57. {
  58. return $this->hasMany(static::class, 'parent_id');
  59. }
  60. /**
  61. * Retrieve type instance.
  62. *
  63. * @return \Webkul\Product\Type\AbstractType
  64. */
  65. public function getTypeInstance()
  66. {
  67. return $this->product->getTypeInstance();
  68. }
  69. }