D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
developers.ghanempharmacy.com
/
app
/
Models
/
Filename :
ShippingAddress.php
back
Copy
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Carbon; /** * Class ShippingAddress * * @property int $id * @property string|null $customer_id * @property bool $is_guest * @property string|null $contact_person_name * @property string|null $email * @property string $address_type * @property string|null $address * @property string|null $city * @property string|null $zip * @property string|null $phone * @property Carbon $created_at * @property Carbon $updated_at * @property string|null $state * @property string|null $country * @property string|null $latitude * @property string|null $longitude * @property bool $is_billing * * @package App\Models */ class ShippingAddress extends Model { protected $guarded = []; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'customer_id', 'is_guest', 'contact_person_name', 'email', 'address_type', 'address', 'city', 'zip', 'phone', 'state', 'country', 'latitude', 'longitude', 'is_billing', 'country_id', 'state_id', 'city_id', 'area_id', 'area_id', 'area', 'village_id', ]; public function village() { return $this->belongsTo(DeliveryVillage::class, 'village_id'); } /** * The attributes that should be appends for JSON. * * @var array */ protected $appends = [ 'country_name', 'state_name', 'city_name', 'area_name', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'is_guest' => 'boolean', 'is_billing' => 'boolean', ]; public function delivery_country(): BelongsTo { return $this->belongsTo(DeliveryCountryCode::class, 'country_id'); } public function delivery_state(): BelongsTo { return $this->belongsTo(DeliveryState::class, 'state_id'); } public function delivery_city(): BelongsTo { return $this->belongsTo(DeliveryCity::class, 'city_id'); } public function delivery_area(): BelongsTo { return $this->belongsTo(DeliveryArea::class, 'area_id'); } public function getCountryNameAttribute(): string { return $this->delivery_country?->name ?? (string) $this->country; } public function getStateNameAttribute(): string { return $this->delivery_state?->name ?? (string) $this->state; } public function getCityNameAttribute(): string { return $this->delivery_city?->name ?? (string) $this->city; } public function getAreaNameAttribute(): string { return $this->area ?? ($this->delivery_area?->name ?? ''); } }