55 lines
1.5 KiB
PHP
Executable File
55 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Company\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Modules\Countries\Models\Country;
|
|
use Modules\Countries\Models\CountrySubdivision;
|
|
|
|
class CompanyAddress extends Model
|
|
{
|
|
protected $fillable = [
|
|
'addressable_type', 'addressable_id', 'label', 'attention', 'line_1', 'line_2', 'line_3',
|
|
'locality', 'administrative_area', 'postal_code', 'country_id', 'country_subdivision_id',
|
|
'latitude', 'longitude', 'is_primary', 'metadata',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_primary' => 'boolean',
|
|
'metadata' => 'array',
|
|
'latitude' => 'decimal:7',
|
|
'longitude' => 'decimal:7',
|
|
];
|
|
|
|
public function addressable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function country(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Country::class);
|
|
}
|
|
|
|
public function subdivision(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CountrySubdivision::class, 'country_subdivision_id');
|
|
}
|
|
|
|
public function getFormattedAttribute(): string
|
|
{
|
|
return collect([
|
|
$this->attention,
|
|
$this->line_1,
|
|
$this->line_2,
|
|
$this->line_3,
|
|
$this->locality,
|
|
$this->administrative_area,
|
|
$this->postal_code,
|
|
$this->country?->effective_name ?? $this->country?->name,
|
|
])->filter()->implode(', ');
|
|
}
|
|
}
|