mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
102 lines
2.3 KiB
PHP
102 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Contactable;
|
|
use App\Classes\General\Interfaces\Remarkable;
|
|
use App\Classes\ValueObjects\Constants\RemarkTypes;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
/**
|
|
* Class Address
|
|
* @package App\Models
|
|
*
|
|
* @property int country_id
|
|
* @property int company_id
|
|
* @property int state_id
|
|
* @property int district_id
|
|
* @property string postcode
|
|
* @property string street_one
|
|
* @property string street_two
|
|
* @property integer billing_type
|
|
*/
|
|
class Address extends AbstractModel implements Contactable, Remarkable
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'addresses';
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
protected $fillable = ['default'];
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function country(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(Country::class, 'country_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function state(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(State::class, 'state_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function district(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(District::class, 'district_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function owner(): morphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeDefaultAddress(Builder $query)
|
|
{
|
|
return $query->where('default', true);
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function contacts(): morphMany
|
|
{
|
|
return $this->morphMany(Contact::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function remarks(): morphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function addressExtraFields(): MorphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner')->where('type', RemarkTypes::ADDRESS_EXTRA_COLUMNS);
|
|
}
|
|
}
|