138 lines
3.2 KiB
PHP
138 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Flight\FlightStoreRequest;
|
|
use App\Models\Airline;
|
|
use App\Models\Airport;
|
|
use App\Models\City;
|
|
use App\Models\Country;
|
|
use App\Models\Flight;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class FlightController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$flights = Flight::query()
|
|
->with([
|
|
'airline',
|
|
'origin_airport.city',
|
|
'airport.city',
|
|
'coverImage.file',
|
|
])
|
|
->when($request->filled('search'), function ($query) use ($request) {
|
|
$search = $request->input('search');
|
|
|
|
$query->whereAny([
|
|
'flight_number',
|
|
''
|
|
], 'like', "%{$search}%");
|
|
})
|
|
->applySort($request->input('sort'))
|
|
->paginate(10)
|
|
->withQueryString();
|
|
|
|
return view('admin.flights.index', compact('flights'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$title = 'ایجاد پرواز';
|
|
|
|
$airlines = Airline::query()
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
$countries = Country::query()
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
$iranCountry = Country::query()
|
|
->where('name', 'iran')
|
|
->first();
|
|
|
|
return view('admin.flights.create', compact(
|
|
'title',
|
|
'airlines',
|
|
'countries',
|
|
'iranCountry'
|
|
));
|
|
|
|
}
|
|
public function citiesByCountry(Country $country): JsonResponse
|
|
{
|
|
$cities = City::query()
|
|
->where('county_id', $country->id)
|
|
->orderBy('name')
|
|
->get([
|
|
'id',
|
|
'name',
|
|
]);
|
|
|
|
return response()->json($cities);
|
|
}
|
|
public function airportsByCity(City $city): JsonResponse
|
|
{
|
|
$airports = Airport::query()
|
|
->where('city_id', $city->id)
|
|
->orderBy('name')
|
|
->get([
|
|
'id',
|
|
'name',
|
|
]);
|
|
|
|
return response()->json($airports);
|
|
}
|
|
|
|
public function store(FlightStoreRequest $request)
|
|
{
|
|
|
|
}
|
|
|
|
public function edit(Flight $flight)
|
|
{
|
|
$title = 'ویرایش پرواز';
|
|
|
|
$flight->load(['origin_airport.city.country', 'airport.city.country']);
|
|
|
|
$airlines = Airline::query()->orderBy('name')->get();
|
|
$countries = Country::query()->orderBy('name')->get();
|
|
|
|
$iranCountry = Country::query()->where('name', 'iran')->first();
|
|
|
|
$originCountryId = $flight->origin_airport?->city?->country?->id;
|
|
$destinationCountryId = $flight->airport?->city?->country?->id;
|
|
|
|
return view('admin.flights.edit', compact(
|
|
'title',
|
|
'flight',
|
|
'airlines',
|
|
'countries',
|
|
'iranCountry',
|
|
'originCountryId',
|
|
'destinationCountryId'
|
|
));
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
|
|
}
|
|
|
|
public function destroy()
|
|
{
|
|
|
|
}
|
|
public function restore()
|
|
{
|
|
|
|
}
|
|
public function forceDelete()
|
|
{
|
|
|
|
}
|
|
}
|