mein-sterntours/app/Models/IQTravelItem.php
2021-08-06 15:28:57 +02:00

131 lines
3 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Class IQTravelItem
*
* @property int $id
* @property string $name
* @property string $description
* @property string $highlights
* @property int $draft_type_id
* @property int $travel_country_id
* @property int $days_start
* @property int $days_duration
* @property int $min_persons
* @property float $price_adult
* @property float $price_children
* @property int $pos
* @property bool $active
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property TravelCountry $travel_country
* @property Collection|IQTravelGroupItem[] $i_q_travel_group_items
* @property Collection|IQTravelItemPlace[] $i_q_travel_item_places
*
* @package App\Models
*/
class IQTravelItem extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'i_q_travel_items';
protected $casts = [
'draft_type_id' => 'int',
'travel_country_id' => 'int',
'days_start' => 'int',
'days_duration' => 'int',
'min_persons' => 'int',
'price_adult' => 'float',
'price_children' => 'float',
'pos' => 'int',
'active' => 'bool'
];
protected $fillable = [
'name',
'description',
'highlights',
'draft_type_id',
'travel_country_id',
'days_start',
'days_duration',
'min_persons',
'price_adult',
'price_children',
'pos',
'active'
];
public function travel_country()
{
return $this->belongsTo(TravelCountry::class);
}
public function i_q_travel_group_items()
{
return $this->hasMany(IQTravelGroupItem::class);
}
public function i_q_travel_item_places()
{
return $this->hasMany(IQTravelItemPlace::class)->orderBy('pos', 'DESC');
}
public function draft_type()
{
return $this->belongsTo(DraftType::class, 'draft_type_id');
}
//price_adult
public function getPriceAdultAttribute()
{
return isset($this->attributes['price_adult']) ? Util::_number_format($this->attributes['price_adult']) : null;
}
public function setPriceAdultAttribute($value)
{
$this->attributes['price_adult'] = $value ? Util::_clean_float($value) : null;
}
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 getPriceChildrenAttribute()
{
return isset($this->attributes['price_children']) ? Util::_number_format($this->attributes['price_children']) : null;
}
public function setPriceChildrenAttribute($value)
{
$this->attributes['price_children'] = $value ? Util::_clean_float($value) : null;
}
public function getPriceChildrenRaw()
{
return isset($this->attributes['price_children']) ? $this->attributes['price_children'] : 0;
}
public function setPriceChildrenRaw($value)
{
return $this->attributes['price_children'] = $value;
}
}