mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
155 lines
4.6 KiB
PHP
155 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Contactable;
|
|
use App\Classes\General\Interfaces\Remarkable;
|
|
use Barryvdh\LaravelIdeHelper\Eloquent;
|
|
use App\Classes\ValueObjects\Constants\RemarkTypes;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
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;
|
|
use Illuminate\Support\Carbon;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
|
|
/**
|
|
* 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
|
|
* @property int $id
|
|
* @property string $owner_type
|
|
* @property int $owner_id
|
|
* @property string|null $reference
|
|
* @property int $type
|
|
* @property int $default
|
|
* @property int $status
|
|
* @property Carbon|null $deleted_at
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property-read Collection|Activity[] $activities
|
|
* @property-read int|null $activities_count
|
|
* @property-read Model|Eloquent $causer
|
|
* @property-read Collection|Contact[] $contacts
|
|
* @property-read int|null $contacts_count
|
|
* @property-read Country|null $country
|
|
* @property-read District|null $district
|
|
* @property-read Model|Eloquent $owner
|
|
* @property-read Collection|Remark[] $remarks
|
|
* @property-read int|null $remarks_count
|
|
* @property-read State|null $state
|
|
* @property-read Model|Eloquent $subject
|
|
* @property-read Model|Eloquent $target
|
|
* @method static Builder|Address defaultAddress()
|
|
* @method static Builder|Address newModelQuery()
|
|
* @method static Builder|Address newQuery()
|
|
* @method static \Illuminate\Database\Query\Builder|Address onlyTrashed()
|
|
* @method static Builder|Address query()
|
|
* @method static Builder|Address whereCountryId($value)
|
|
* @method static Builder|Address whereCreatedAt($value)
|
|
* @method static Builder|Address whereDefault($value)
|
|
* @method static Builder|Address whereDeletedAt($value)
|
|
* @method static Builder|Address whereDistrictId($value)
|
|
* @method static Builder|Address whereId($value)
|
|
* @method static Builder|Address whereOwnerId($value)
|
|
* @method static Builder|Address whereOwnerType($value)
|
|
* @method static Builder|Address wherePostcode($value)
|
|
* @method static Builder|Address whereReference($value)
|
|
* @method static Builder|Address whereStateId($value)
|
|
* @method static Builder|Address whereStatus($value)
|
|
* @method static Builder|Address whereStreetOne($value)
|
|
* @method static Builder|Address whereStreetTwo($value)
|
|
* @method static Builder|Address whereType($value)
|
|
* @method static Builder|Address whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Query\Builder|Address withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|Address withoutTrashed()
|
|
* @mixin Eloquent
|
|
*/
|
|
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 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')->whereNull('type');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function addressExtraFields(): MorphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner')->where('type', RemarkTypes::ADDRESS_EXTRA_COLUMNS);
|
|
}
|
|
}
|