belongsTo('App\Models\Booking', 'booking_id'); } */ public function booking() { return $this->belongsTo('App\Models\Booking', 'booking_id'); } public function draft_item() { return $this->belongsTo('App\Models\DraftItem', 'draft_item_id'); } public function draft_type() { return $this->belongsTo('App\Models\DraftType', 'draft_type_id'); } public function getItemPrice(){ $adult = 0; $children = 0; $days_duration = 1; if(isset($this->attributes['days_duration']) && in_array($this->draft_type_id, [36, 37])){ $days_duration = intval($this->days_duration); } if(isset($this->attributes['adult'])){ $adult = $this->attributes['price_adult'] * $this->attributes['adult'] * $days_duration; } if(isset($this->attributes['children'])){ $children = $this->attributes['price_children'] * $this->attributes['children'] * $days_duration; } /* if(in_array($this->draft_type_id, [38, 39,40])){ $days_duration = $this->days_duration; $price = $this->price; } */ return ['adult'=>$adult, 'children'=>$children]; } public function getStartDateAttribute(){ return isset($this->attributes['start_date']) ? Carbon::parse($this->attributes['start_date'])->format("d.m.Y") : ''; } public function getEndDateAttribute(){ return isset($this->attributes['end_date']) ? Carbon::parse($this->attributes['end_date'])->format("d.m.Y") : ''; } public function setStartDateAttribute($value) { if (!$value) { $this->attributes['start_date'] = null; } else { $this->attributes['start_date'] = (new Carbon($value))->format('Y-m-d'); } } public function setEndDateAttribute($value){ if (!$value) { $this->attributes['end_date'] = null; } else { $this->attributes['end_date'] = (new Carbon($value))->format('Y-m-d'); } } //price_adult public function setPriceAdultAttribute($value) { $this->attributes['price_adult'] = Util::_clean_float($value); } public function getPriceAdultAttribute() { // 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator return number_format(($this->attributes['price_adult']), 2, ',', '.'); } public function getPriceAdultRaw() { return isset($this->attributes['price_adult']) ? $this->attributes['price_adult'] : 0; } public function setPriceAdultRaw($value) { return $this->attributes['price_adult'] = $value; } //price_children public function setPriceChildrenAttribute($value) { $this->attributes['price_children'] = Util::_clean_float($value); } public function getPriceChildrenAttribute() { // 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator return number_format(($this->attributes['price_children']), 2, ',', '.'); } public function getPriceChildrenRaw() { return isset($this->attributes['price_children']) ? $this->attributes['price_children'] : 0; } public function setPriceChildrenRaw($value) { return $this->attributes['price_children'] = $value; } //price public function setPriceAttribute($value) { $this->attributes['price'] = Util::_clean_float($value); } public function getPriceAttribute() { // 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator return number_format(($this->attributes['price']), 2, ',', '.'); } public function getPriceRaw() { return isset($this->attributes['price']) ? $this->attributes['price'] : 0; } public function setPriceRaw($value) { return $this->attributes['price'] = $value; } }