fix: update travel models

This commit is contained in:
2026-08-19 08:11:32 +03:30
parent 4aa2e9fb65
commit a9d46fe64c
3 changed files with 64 additions and 80 deletions
+5 -3
View File
@@ -6,6 +6,7 @@
namespace App\Models; namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
/** /**
@@ -14,21 +15,22 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id * @property int $id
* @property string $name * @property string $name
* @property string $city * @property string $city
* @property string $country * @property string $province
* @property string $code * @property string $code
* @property Carbon $created_at
* @property Carbon $updated_at
* *
* @package App\Models * @package App\Models
*/ */
class Airport extends Model class Airport extends Model
{ {
protected $table = 'airports'; protected $table = 'airports';
public $timestamps = false;
public static $snakeAttributes = false; public static $snakeAttributes = false;
protected $fillable = [ protected $fillable = [
'name', 'name',
'city', 'city',
'country', 'province',
'code' 'code'
]; ];
} }
+12
View File
@@ -45,6 +45,18 @@ class Flight extends Model
'status', 'status',
]; ];
// مبدا پرواز
public function origin()
{
return $this->belongsTo(Airport::class, 'origin_airport_id');
}
// مقصد پرواز
public function destination()
{
return $this->belongsTo(Airport::class, 'destination_airport_id');
}
/* ------------------------- روابط (Relations) ------------------------- */ /* ------------------------- روابط (Relations) ------------------------- */
/** /**
+47 -77
View File
@@ -12,97 +12,67 @@ use Illuminate\Database\Eloquent\Model;
/** /**
* Class Tour * Class Tour
* *
* @property int $id * @property int $id
* @property int $travel_type_id * @property int|null $travel_type_id
* @property string $title * @property string $title
* @property string $slug * @property string|null $slug
* @property string $description * @property string|null $image
* @property string $duration * @property string|null $description
* @property Carbon $start_date * @property string|null $duration
* @property Carbon $end_date * @property Carbon|null $start_date
* @property Carbon|null $end_date
* @property float $price * @property float $price
* @property int $capacity * @property int|null $capacity
* @property int $views_count
* @property int $status * @property int $status
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
* *
* @property TravelType $travelType * @property TravelType|null $travelType
* @property Collection|Flight[] $flights * @property Collection|Flight[] $flights
* *
* @package App\Models * @package App\Models
*/ */
class Tour extends Model class Tour extends Model
{ {
protected $table = 'tours'; protected $table = 'tours';
public static $snakeAttributes = false; public static $snakeAttributes = false;
protected $casts = [ protected $casts = [
'start_date' => 'date', 'travel_type_id' => 'int',
'end_date' => 'date', 'start_date' => 'datetime',
'price' => 'decimal:2', 'end_date' => 'datetime',
'status' => 'integer', 'price' => 'float',
'capacity' => 'int',
'views_count' => 'int',
'status' => 'int'
];
// 'travel_type_id' => 'int', protected $fillable = [
// 'start_date' => 'datetime', 'travel_type_id',
// 'end_date' => 'datetime', 'title',
// 'price' => 'float', 'slug',
// 'capacity' => 'int', 'image',
// 'status' => 'int' 'description',
]; 'duration',
'start_date',
protected $fillable = [ 'end_date',
'travel_type_id', 'price',
'title', 'capacity',
'slug', 'views_count',
'description', 'status'
'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 ? 'فعال' : 'پیش‌نویس';
}
public function travelType()
{
return $this->belongsTo(TravelType::class);
}
public function flights()
{
return $this->belongsToMany(Flight::class, 'tour_flights')
->withPivot('id')
->withTimestamps();
}
} }