belongsTo(Customer::class, 'customer_id'); } /** * Company the address was recorded under. */ public function company(): BelongsTo { return $this->belongsTo(Company::class, 'company_id'); } /** * User the address belongs to, for addresses owned by a team member. */ public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } /** * Country reference row this address sits in. */ public function country(): BelongsTo { return $this->belongsTo(Country::class, 'country_id'); } /** * Country name rendered in the language the application is running in. * * Falls back to the name stored in the reference table whenever the ICU * catalogue has nothing for the stored code. */ public function getCountryNameAttribute(): ?string { $country = $this->country; if (! $country) { return null; } try { return Countries::getName($country->code, app()->getLocale()); } catch (\Exception $exception) { return $country->name; } } }