Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Client.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 currency(): BelongsTo
  33. {
  34. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  35. }
  36. public function addresses(): MorphMany
  37. {
  38. return $this->morphMany(Address::class, 'addressable');
  39. }
  40. public function billingAddress(): MorphOne
  41. {
  42. return $this->morphOne(Address::class, 'addressable')
  43. ->where('type', AddressType::Billing);
  44. }
  45. public function shippingAddress(): MorphOne
  46. {
  47. return $this->morphOne(Address::class, 'addressable')
  48. ->where('type', AddressType::Shipping);
  49. }
  50. }