Files
shahrzadzandi09/app/Http/Controllers/FlightController.php
T
2026-08-19 08:07:01 +03:30

272 lines
6.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Flight;
use Illuminate\Http\Request;
class FlightController extends Controller
{
/**
* لیست پروازها
*/
public function index(Request $request)
{
$query = Flight::query()
->with([
'travelType',
'origin',
'destination',
]);
// فقط پروازهای فعال
$query->where('status', 1);
// جستجو بر اساس شماره پرواز
if ($request->filled('flight_number')) {
$query->where(
'flight_number',
'like',
'%' . $request->flight_number . '%'
);
}
// جستجو بر اساس مبدا
if ($request->filled('origin')) {
$query->where(
'origin',
'like',
'%' . $request->origin . '%'
);
}
// جستجو بر اساس مقصد
if ($request->filled('destination')) {
$query->where(
'destination',
'like',
'%' . $request->destination . '%'
);
}
$flights = $query
->latest()
->paginate(12)
->withQueryString();
return view('flights.index', compact('flights'));
}
/**
* جستجوی پروازها
*/
public function search(Request $request)
{
$query = Flight::query()
->where('status', 1)
->with([
'travelType',
'origin',
'destination',
]);
if ($request->filled('origin')) {
$query->where(
'origin',
'like',
'%' . $request->origin . '%'
);
}
if ($request->filled('destination')) {
$query->where(
'destination',
'like',
'%' . $request->destination . '%'
);
}
if ($request->filled('departure_date')) {
$query->where(
'departure_date',
$request->departure_date
);
}
if ($request->filled('flight_number')) {
$query->where(
'flight_number',
'like',
'%' . $request->flight_number . '%'
);
}
$flights = $query
->latest()
->paginate(12)
->withQueryString();
return view('flights.index', compact('flights'));
}
/**
* جزئیات پرواز
*/
public function show(Flight $flight)
{
/*
|--------------------------------------------------------------------------
| فعلاً isActive را حذف کردیم
|--------------------------------------------------------------------------
| چون اگر متد isActive در مدل اشتباه باشد یا status متفاوت باشد
| باعث 404 شدن صفحه می‌شود.
*/
$flight->load([
'travelType',
'origin',
'destination',
'tours',
]);
return view('flights.show', compact('flight'));
}
}
//
//namespace App\Http\Controllers;
//
//use App\Models\Flight;
//use Illuminate\Http\Request;
//
//class FlightController extends Controller
//{
// /**
// * لیست پروازها
// */
// public function index(Request $request)
// {
// $query = Flight::query()
// ->where('status', 1)
// ->with([
// 'travelType',
// 'origin',
// 'destination',
// ]);
//
// // جستجو بر اساس شماره پرواز
// if ($request->filled('flight_number')) {
// $query->where(
// 'flight_number',
// 'like',
// '%' . $request->input('flight_number') . '%'
// );
// }
//
// // جستجو بر اساس مبدا
// if ($request->filled('origin')) {
// $query->where(
// 'origin',
// 'like',
// '%' . $request->input('origin') . '%'
// );
// }
//
// // جستجو بر اساس مقصد
// if ($request->filled('destination')) {
// $query->where(
// 'destination',
// 'like',
// '%' . $request->input('destination') . '%'
// );
// }
//
// // مرتب‌سازی
// $flights = $query
// ->latest()
// ->paginate(12)
// ->withQueryString();
//
// return view(
// 'flights.index',
// compact('flights')
// );
// }
//
//
// /**
// * جستجوی پروازها
// */
// public function search(Request $request)
// {
// $query = Flight::query()
// ->where('status', 1)
// ->with([
// 'travelType',
// 'origin',
// 'destination',
// ]);
//
// if ($request->filled('origin')) {
// $query->where(
// 'origin',
// 'like',
// '%' . $request->input('origin') . '%'
// );
// }
//
// if ($request->filled('destination')) {
// $query->where(
// 'destination',
// 'like',
// '%' . $request->input('destination') . '%'
// );
// }
//
// if ($request->filled('departure_date')) {
// $query->where(
// 'departure_date',
// $request->input('departure_date')
// );
// }
//
// $flights = $query
// ->latest()
// ->paginate(12)
// ->withQueryString();
//
// return view(
// 'flights.index',
// compact('flights')
// );
// }
//
//
// /**
// * جزئیات پرواز
// */
// public function show(Flight $flight)
// {
// // فقط پروازهای فعال قابل مشاهده باشند
// if (!$flight->isActive()) {
// abort(404);
// }
//
// // اطلاعات مورد نیاز پرواز
// $flight->load([
// 'travelType',
// 'origin',
// 'destination',
// 'tours',
// ]);
//
// return view(
// 'flights.show',
// compact('flight')
// );
// }
//}