您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Client.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Enums\Common\AddressType;
  6. use App\Models\Setting\Currency;
  7. use Illuminate\Database\Eloquent\Factories\HasFactory;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\MorphMany;
  11. use Illuminate\Database\Eloquent\Relations\MorphOne;
  12. class Client extends Model
  13. {
  14. use Blamable;
  15. use CompanyOwned;
  16. use HasFactory;
  17. protected $table = 'clients';
  18. protected $fillable = [
  19. 'company_id',
  20. 'name',
  21. 'currency_code',
  22. 'account_number',
  23. 'website',
  24. 'notes',
  25. 'created_by',
  26. 'updated_by',
  27. ];
  28. public function contacts(): MorphMany
  29. {
  30. return $this->morphMany(Contact::class, 'contactable');
  31. }
  32. public function primaryContact(): MorphOne
  33. {
  34. return $this->morphOne(Contact::class, 'contactable')
  35. ->where('is_primary', true);
  36. }
  37. public function secondaryContacts(): MorphMany
  38. {
  39. return $this->morphMany(Contact::class, 'contactable')
  40. ->where('is_primary', false);
  41. }
  42. public function currency(): BelongsTo
  43. {
  44. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  45. }
  46. public function addresses(): MorphMany
  47. {
  48. return $this->morphMany(Address::class, 'addressable');
  49. }
  50. public function billingAddress(): MorphOne
  51. {
  52. return $this->morphOne(Address::class, 'addressable')
  53. ->where('type', AddressType::Billing);
  54. }
  55. public function shippingAddress(): MorphOne
  56. {
  57. return $this->morphOne(Address::class, 'addressable')
  58. ->where('type', AddressType::Shipping);
  59. }
  60. }