Files
shahrzadzandi09/app/Models/Tour.php
T
2026-08-17 19:53:12 +03:30

109 lines
2.2 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* Class Tour
*
* @property int $id
* @property int $travel_type_id
* @property string $title
* @property string $slug
* @property string $description
* @property string $duration
* @property Carbon $start_date
* @property Carbon $end_date
* @property float $price
* @property int $capacity
* @property int $status
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property TravelType $travelType
* @property Collection|Flight[] $flights
*
* @package App\Models
*/
class Tour extends Model
{
protected $table = 'tours';
public static $snakeAttributes = false;
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
'price' => 'decimal:2',
'status' => 'integer',
// 'travel_type_id' => 'int',
// 'start_date' => 'datetime',
// 'end_date' => 'datetime',
// 'price' => 'float',
// 'capacity' => 'int',
// 'status' => 'int'
];
protected $fillable = [
'travel_type_id',
'title',
'slug',
'description',
'duration',
'start_date',
'end_date',
'price',
'capacity',
'status',
'image',
];
public function travelType()
{
return $this->belongsTo(TravelType::class);
}
public function flights()
{
return $this->belongsToMany(Flight::class, 'tour_flights')
->withPivot('id')
->withTimestamps();
}
//اضافه شده (بعدا بررسی بشه)
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
public function favorites()
{
return $this->morphMany(Favorite::class, 'favoritable');
}
public function files()
{
return $this->morphMany(File::class, 'fileable');
}
public function getRouteKeyName()
{
return 'slug';
}
public function getStatusLabelAttribute()
{
return $this->status == 1 ? 'فعال' : 'پیش‌نویس';
}
}