129 lines
2.8 KiB
PHP
129 lines
2.8 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()
|
|
->active()
|
|
->with([
|
|
'travelType',
|
|
'tours',
|
|
]);
|
|
|
|
// شماره پرواز
|
|
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()
|
|
->active()
|
|
->with([
|
|
'travelType',
|
|
'tours',
|
|
]);
|
|
|
|
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->whereDate(
|
|
'departure_date',
|
|
$request->input('departure_date')
|
|
);
|
|
}
|
|
|
|
if ($request->filled('flight_number')) {
|
|
$query->where(
|
|
'flight_number',
|
|
'like',
|
|
'%' . $request->input('flight_number') . '%'
|
|
);
|
|
}
|
|
|
|
$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',
|
|
'tours',
|
|
]);
|
|
|
|
return view('flights.show', compact('flight'));
|
|
}
|
|
}
|