Customer.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Shop\Customers;
  3. use App\Shop\Addresses\Address;
  4. use App\Shop\Orders\Order;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Notifications\Notifiable;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use Laravel\Cashier\Billable;
  9. use Nicolaslopezj\Searchable\SearchableTrait;
  10. class Customer extends Authenticatable
  11. {
  12. use Notifiable, SoftDeletes, SearchableTrait, Billable;
  13. /**
  14. * The attributes that are mass assignable.
  15. *
  16. * @var array
  17. */
  18. protected $fillable = [
  19. 'name',
  20. 'email',
  21. 'password',
  22. 'status'
  23. ];
  24. /**
  25. * The attributes that should be hidden for arrays.
  26. *
  27. * @var array
  28. */
  29. protected $hidden = [
  30. 'password',
  31. 'remember_token',
  32. ];
  33. protected $dates = ['deleted_at'];
  34. /**
  35. * Searchable rules.
  36. *
  37. * @var array
  38. */
  39. protected $searchable = [
  40. 'columns' => [
  41. 'customers.name' => 10,
  42. 'customers.email' => 5
  43. ]
  44. ];
  45. /**
  46. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  47. */
  48. public function addresses()
  49. {
  50. return $this->hasMany(Address::class)->whereStatus(true);
  51. }
  52. /**
  53. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  54. */
  55. public function orders()
  56. {
  57. return $this->hasMany(Order::class);
  58. }
  59. /**
  60. * @param $term
  61. *
  62. * @return mixed
  63. */
  64. public function searchCustomer($term)
  65. {
  66. return self::search($term);
  67. }
  68. }