'int', 'auth_user_id' => 'int', 'is_host' => 'bool', 'billing_country_id' => 'int', 'same_as_billing' => 'bool', 'shipping_country_id' => 'int', 'has_buyed' => 'bool', 'subscribed' => 'bool', 'settings' => 'array', ]; protected $dates = [ 'user_deleted_at' ]; protected $fillable = [ 'homeparty_id', 'auth_user_id', 'is_host', 'billing_salutation', 'billing_company', 'billing_firstname', 'billing_lastname', 'billing_address', 'billing_address_2', 'billing_zipcode', 'billing_city', 'billing_country_id', 'billing_phone', 'billing_email', 'same_as_billing', 'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_phone', 'shipping_email', 'has_buyed', 'subscribed', 'notice', 'mode', 'settings', 'delivery', 'user_deleted_at' ]; public function homeparty() { return $this->belongsTo(Homeparty::class); } public function auth_user() { return $this->belongsTo(User::class, 'auth_user_id'); } public function billing_country() { return $this->belongsTo('App\Models\Country','billing_country_id'); } public function shipping_country() { return $this->belongsTo('App\Models\Country','shipping_country_id'); } public function homeparty_user_order_items(){ return $this->hasMany('App\Models\HomepartyUserOrderItem','homeparty_user_id'); } public function isAddress(){ if($this->billing_firstname !== null && $this->billing_country_id !== null){ return true; } return false; } public function getDelivery(){ return $this->delivery === 'direct' ? 'direct' : 'host'; } public function getShipping(){ if($this->same_as_billing){ $country_id = $this->billing_country_id != null ? $this->billing_country_id : 1; }else{ $country_id = $this->shipping_country_id != null ? $this->shipping_country_id : 1; } $shippingCountry = ShippingCountry::whereCountryId($country_id)->first(); if(!$shippingCountry){ return null; } return $shippingCountry->shipping; } }