'int', 'completed' => 'int', 'status' => 'int', 'step' => 'int', 'country_id' => 'int', 'order_to' => 'bool', 'active' => 'bool', 'default' => 'bool', 'token_active' => 'bool', 'settings' => 'array', 'order' => 'array', 'card_info' => 'array', ]; protected $dates = [ 'date' ]; protected $hidden = [ 'token' ]; protected $fillable = [ 'auth_user_id', 'date', 'name', 'place', 'country_id', 'description', 'pos', 'completed', 'status', 'step', 'order_to', 'active', 'default', 'token', 'token_active', 'settings', 'order', 'card_info' ]; private $user_country; public function auth_user() { return $this->belongsTo('App\User', 'auth_user_id'); } public function country() { return $this->belongsTo('App\Models\Country', 'country_id'); } public function homeparty_users() { return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id'); } public function homeparty_host() { return $this->hasOne('App\Models\HomepartyUser', 'homeparty_id')->where('is_host', true); } public function homeparty_guests() { return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id')->where('is_host', false); } public function homeparty_order_items(){ return $this->hasMany('App\Models\HomepartyUserOrderItem','homeparty_id'); } public function getDateAttribute($value) { if (!$value) { return ""; } return Carbon::parse($value)->format(\Util::formatDateDB()); } public function setDateAttribute($value) { $this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL; } public function getTokenLink(){ return url('homeparty/'.$this->token); } public function getCardInfo($key) { return isset($this->card_info[$key]) ? $this->card_info[$key] : null; } public function getUserCountry(){ if(!$this->user_country){ if($user_country_id = $this->getCardInfo('user_country_id')){ $this->user_country = Country::findOrFail($user_country_id); } } return $this->user_country; } public function isPriceCurrency() { $user_country = $this->getUserCountry(); return ($user_country && $user_country->currency) ? true : false; } public function getPriceCurrencyUnit() { $user_country = $this->getUserCountry(); return ($user_country && $user_country->currency) ? $user_country->currency_unit : false; } }