diff --git a/app/Http/Controllers/FlightController.php b/app/Http/Controllers/FlightController.php index cf6339f..ebb4e5d 100644 --- a/app/Http/Controllers/FlightController.php +++ b/app/Http/Controllers/FlightController.php @@ -9,44 +9,41 @@ use Illuminate\Http\Request; class FlightController extends Controller { /** - * لیست پروازها + * لیست پروازهای فعال */ public function index(Request $request) { $query = Flight::query() + ->active() ->with([ 'travelType', - 'origin', - 'destination', + 'tours', ]); - // فقط پروازهای فعال - $query->where('status', 1); - - // جستجو بر اساس شماره پرواز + // شماره پرواز if ($request->filled('flight_number')) { $query->where( 'flight_number', 'like', - '%' . $request->flight_number . '%' + '%' . $request->input('flight_number') . '%' ); } - // جستجو بر اساس مبدا + // مبدا if ($request->filled('origin')) { $query->where( 'origin', 'like', - '%' . $request->origin . '%' + '%' . $request->input('origin') . '%' ); } - // جستجو بر اساس مقصد + // مقصد if ($request->filled('destination')) { $query->where( 'destination', 'like', - '%' . $request->destination . '%' + '%' . $request->input('destination') . '%' ); } @@ -65,18 +62,17 @@ class FlightController extends Controller public function search(Request $request) { $query = Flight::query() - ->where('status', 1) + ->active() ->with([ 'travelType', - 'origin', - 'destination', + 'tours', ]); if ($request->filled('origin')) { $query->where( 'origin', 'like', - '%' . $request->origin . '%' + '%' . $request->input('origin') . '%' ); } @@ -84,14 +80,14 @@ class FlightController extends Controller $query->where( 'destination', 'like', - '%' . $request->destination . '%' + '%' . $request->input('destination') . '%' ); } if ($request->filled('departure_date')) { - $query->where( + $query->whereDate( 'departure_date', - $request->departure_date + $request->input('departure_date') ); } @@ -99,7 +95,7 @@ class FlightController extends Controller $query->where( 'flight_number', 'like', - '%' . $request->flight_number . '%' + '%' . $request->input('flight_number') . '%' ); } @@ -117,155 +113,16 @@ class FlightController extends Controller */ public function show(Flight $flight) { - /* - |-------------------------------------------------------------------------- - | فعلاً isActive را حذف کردیم - |-------------------------------------------------------------------------- - | چون اگر متد isActive در مدل اشتباه باشد یا status متفاوت باشد - | باعث 404 شدن صفحه می‌شود. - */ +// // فقط پرواز فعال قابل مشاهده باشد +// if (!$flight->isActive()) { +// abort(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') -// ); -// } -//}