Address.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Shop\Addresses;
  3. use App\Shop\Customers\Customer;
  4. use App\Shop\Orders\Order;
  5. use App\Shop\Provinces\Province;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. use App\Shop\Cities\City;
  9. use App\Shop\Countries\Country;
  10. use Nicolaslopezj\Searchable\SearchableTrait;
  11. class Address extends Model
  12. {
  13. use SoftDeletes, SearchableTrait;
  14. /**
  15. * The attributes that are mass assignable.
  16. *
  17. * @var array
  18. */
  19. public $fillable = [
  20. 'alias',
  21. 'address_1',
  22. 'address_2',
  23. 'zip',
  24. 'city',
  25. 'state_code',
  26. 'province_id',
  27. 'country_id',
  28. 'customer_id',
  29. 'status',
  30. 'phone'
  31. ];
  32. /**
  33. * The attributes that should be hidden for arrays.
  34. *
  35. * @var array
  36. */
  37. protected $hidden = [];
  38. protected $dates = ['deleted_at'];
  39. /**
  40. * Searchable rules.
  41. *
  42. * @var array
  43. */
  44. protected $searchable = [
  45. 'columns' => [
  46. 'alias' => 5,
  47. 'address_1' => 10,
  48. 'address_2' => 5,
  49. 'zip' => 5,
  50. 'city' => 10,
  51. 'state_code' => 10,
  52. 'phone' => 5
  53. ]
  54. ];
  55. public function customer()
  56. {
  57. return $this->belongsTo(Customer::class);
  58. }
  59. public function country()
  60. {
  61. return $this->belongsTo(Country::class);
  62. }
  63. public function province()
  64. {
  65. return $this->belongsTo(Province::class);
  66. }
  67. /**
  68. * @deprecated
  69. *
  70. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  71. */
  72. public function city()
  73. {
  74. return $this->belongsTo(City::class, 'city');
  75. }
  76. /**
  77. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  78. */
  79. public function orders()
  80. {
  81. return $this->hasMany(Order::class);
  82. }
  83. /**
  84. * @param $term
  85. *
  86. * @return mixed
  87. */
  88. public function searchAddress($term)
  89. {
  90. return self::search($term);
  91. }
  92. }