93 lines
1.6 KiB
PHP
93 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Flight extends Model
|
|
{
|
|
protected $table = 'flights';
|
|
|
|
protected $casts = [
|
|
'travel_type_id' => 'integer',
|
|
|
|
'departure_date' => 'date',
|
|
'arrival_date' => 'date',
|
|
|
|
'departure_time' => 'datetime',
|
|
'arrival_time' => 'datetime',
|
|
|
|
'price' => 'decimal:2',
|
|
|
|
'capacity' => 'integer',
|
|
'status' => 'integer',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'travel_type_id',
|
|
'flight_number',
|
|
'airline_name',
|
|
'origin',
|
|
'destination',
|
|
'departure_date',
|
|
'departure_time',
|
|
'arrival_date',
|
|
'arrival_time',
|
|
'duration',
|
|
'price',
|
|
'capacity',
|
|
'status',
|
|
];
|
|
|
|
|
|
|
|
|
|
public function travelType()
|
|
{
|
|
return $this->belongsTo(
|
|
TravelType::class,
|
|
'travel_type_id'
|
|
);
|
|
}
|
|
|
|
|
|
public function tours()
|
|
{
|
|
return $this->belongsToMany(
|
|
Tour::class,
|
|
'tour_flights'
|
|
)
|
|
->withPivot('id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return (int)$this->status === 1
|
|
? 'فعال'
|
|
: 'غیرفعال';
|
|
}
|
|
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return (int)$this->status === 1;
|
|
}
|
|
|
|
|
|
|
|
#[Scope]
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('status', 1);
|
|
}
|
|
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'id';
|
|
}
|
|
}
|