Order.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Shop\Orders;
  3. use App\Shop\Addresses\Address;
  4. use App\Shop\Couriers\Courier;
  5. use App\Shop\Customers\Customer;
  6. use App\Shop\OrderStatuses\OrderStatus;
  7. use App\Shop\Products\Product;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Nicolaslopezj\Searchable\SearchableTrait;
  10. class Order extends Model
  11. {
  12. use SearchableTrait;
  13. /**
  14. * Searchable rules.
  15. *
  16. * Columns and their priority in search results.
  17. * Columns with higher values are more important.
  18. * Columns with equal values have equal importance.
  19. *
  20. * @var array
  21. */
  22. protected $searchable = [
  23. 'columns' => [
  24. 'customers.name' => 10,
  25. 'orders.reference' => 8,
  26. 'products.name' => 5
  27. ],
  28. 'joins' => [
  29. 'customers' => ['customers.id', 'orders.customer_id'],
  30. 'order_product' => ['orders.id', 'order_product.order_id'],
  31. 'products' => ['products.id', 'order_product.product_id'],
  32. ],
  33. 'groupBy' => ['orders.id']
  34. ];
  35. /**
  36. * The attributes that are mass assignable.
  37. *
  38. * @var array
  39. */
  40. protected $fillable = [
  41. 'reference',
  42. 'courier_id', // @deprecated
  43. 'courier',
  44. 'customer_id',
  45. 'address_id',
  46. 'order_status_id',
  47. 'payment',
  48. 'discounts',
  49. 'total_products',
  50. 'total',
  51. 'tax',
  52. 'total_paid',
  53. 'invoice',
  54. 'label_url',
  55. 'tracking_number',
  56. 'total_shipping'
  57. ];
  58. /**
  59. * The attributes that should be hidden for arrays.
  60. *
  61. * @var array
  62. */
  63. protected $hidden = [];
  64. /**
  65. * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
  66. */
  67. public function products()
  68. {
  69. return $this->belongsToMany(Product::class)
  70. ->withPivot([
  71. 'quantity',
  72. 'product_name',
  73. 'product_sku',
  74. 'product_description',
  75. 'product_price',
  76. 'product_attribute_id'
  77. ]);
  78. }
  79. /**
  80. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  81. */
  82. public function customer()
  83. {
  84. return $this->belongsTo(Customer::class);
  85. }
  86. /**
  87. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  88. */
  89. public function courier()
  90. {
  91. return $this->belongsTo(Courier::class);
  92. }
  93. /**
  94. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  95. */
  96. public function address()
  97. {
  98. return $this->belongsTo(Address::class);
  99. }
  100. /**
  101. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  102. */
  103. public function orderStatus()
  104. {
  105. return $this->belongsTo(OrderStatus::class);
  106. }
  107. /**
  108. * @param string $term
  109. *
  110. * @return mixed
  111. */
  112. public function searchForOrder(string $term)
  113. {
  114. return self::search($term);
  115. }
  116. }