fix: update flight functionality

This commit is contained in:
2026-08-20 08:19:33 +03:30
parent 39386b8155
commit 99e7d4ee95
2 changed files with 118 additions and 114 deletions
+25 -112
View File
@@ -1,32 +1,27 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Model;
/**
* Class Flight
*/
class Flight extends Model
{
protected $table = 'flights';
protected $casts = [
'travel_type_id' => 'int',
'travel_type_id' => 'integer',
'departure_date' => 'date',
'arrival_date' => 'date',
'departure_time' => 'datetime',
'arrival_time' => 'datetime',
'price' => 'decimal:2',
'capacity' => 'int',
'status' => 'int',
'capacity' => 'integer',
'status' => 'integer',
];
protected $fillable = [
@@ -45,135 +40,53 @@ class Flight extends Model
'status',
];
// مبدا پرواز
public function origin()
{
return $this->belongsTo(Airport::class, 'origin_airport_id');
}
// مقصد پرواز
public function destination()
{
return $this->belongsTo(Airport::class, 'destination_airport_id');
}
/* ------------------------- روابط (Relations) ------------------------- */
/**
* نوع سفر (داخلی/خارجی/چارتر) مرتبط با این پرواز
*/
public function travelType()
{
return $this->belongsTo(TravelType::class);
return $this->belongsTo(
TravelType::class,
'travel_type_id'
);
}
/**
* تورهای مرتبط با این پرواز
*/
public function tours()
{
return $this->belongsToMany(Tour::class, 'tour_flights')
return $this->belongsToMany(
Tour::class,
'tour_flights'
)
->withPivot('id')
->withTimestamps();
}
/* --------------------------- Helper ها ------------------------------ */
public function statusLabel(): string
{
return $this->status == 1 ? 'فعال' : 'غیرفعال';
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';
}
}
//
///**
// * Created by Reliese Model.
// */
//
//namespace App\Models;
//
//use Carbon\Carbon;
//use Illuminate\Database\Eloquent\Collection;
//use Illuminate\Database\Eloquent\Model;
//
///**
// * Class Flight
// *
// * @property int $id
// * @property int $travel_type_id
// * @property string $flight_number
// * @property string $airline_name
// * @property string $origin
// * @property string $destination
// * @property Carbon $departure_date
// * @property Carbon $departure_time
// * @property Carbon $arrival_date
// * @property Carbon $arrival_time
// * @property string $duration
// * @property float $price
// * @property int $capacity
// * @property int $status
// * @property Carbon $created_at
// * @property Carbon $updated_at
// *
// * @property Collection|Tour[] $tours
// *
// * @package App\Models
// */
//class Flight extends Model
//{
// protected $table = 'flights';
// public static $snakeAttributes = false;
//
// protected $casts = [
// 'travel_type_id' => 'int',
// 'departure_date' => 'datetime',
// 'departure_time' => 'datetime',
// 'arrival_date' => 'datetime',
// 'arrival_time' => 'datetime',
// 'price' => 'float',
// 'capacity' => 'int',
// 'status' => 'int'
// ];
//
// 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 tours()
// {
// return $this->belongsToMany(Tour::class, 'tour_flights')
// ->withPivot('id')
// ->withTimestamps();
// }
//}
+93 -2
View File
@@ -1,3 +1,94 @@
<div>
<!-- We must ship. - Taylor Otwell -->
<div class="col-md-12">
<div class="theme-search-results-item">
<div class="theme-search-results-item-preview">
<div class="row">
<div class="col-md-2">
<div class="theme-search-results-item-flight-logo">
<i class="fa fa-plane fa-2x"></i>
<h5>
{{ $airline }}
</h5>
</div>
</div>
<div class="col-md-2">
<h4>
{{ $departure }}
</h4>
<p>
{{ $from }}
</p>
</div>
<div class="col-md-2 text-center">
<i class="fa fa-long-arrow-right"></i>
<p>
پرواز مستقیم
</p>
</div>
<div class="col-md-2">
<h4>
{{ $arrival }}
</h4>
<p>
{{ $to }}
</p>
</div>
<div class="col-md-2">
<strong>
{{ $price }}
</strong>
<small>
تومان
</small>
</div>
<div class="col-md-2">
<a
href="{{ url('/flights/1') }}"
class="btn btn-primary btn-block">
جزئیات
</a>
</div>
</div>
</div>
</div>
</div>