98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admins\FlightUpdatePostRequest;
|
|
use App\Models\Airline;
|
|
use App\Models\Airport;
|
|
use App\Models\Flight;
|
|
use Hekmatinasser\Verta\Verta;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FlightController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$flights = Flight::query()
|
|
->with([
|
|
'airline',
|
|
'airport',
|
|
'destinationAirport',
|
|
])
|
|
->latest('id')
|
|
->paginate(10);
|
|
foreach ($flights as $flight) {
|
|
$flight->start_date_fa = $flight->start_time
|
|
? $flight->start_time->toJalali()->format('Y/m/d')
|
|
: null;
|
|
|
|
$flight->end_date_fa = $flight->end_time
|
|
? $flight->end_time->toJalali()->format('Y/m/d')
|
|
: null;
|
|
|
|
$flight->start_time_fa = $flight->start_time
|
|
? $flight->start_time->format('H:i')
|
|
: null;
|
|
|
|
$flight->end_time_fa = $flight->end_time
|
|
? $flight->end_time->format('H:i')
|
|
: null;
|
|
}
|
|
return view('admin.flights.index', compact('flights'));
|
|
}
|
|
public function edit(Flight $flight)
|
|
{
|
|
$airlines = Airline::query()
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
$airports = Airport::query()
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return view('admin.flights.edit', compact('flight', 'airlines', 'airports'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified flight.
|
|
*/
|
|
public function update(FlightUpdatePostRequest $request, Flight $flight)
|
|
{
|
|
$data = $request->validated();
|
|
|
|
$start = verta::parse($data['start_time'])->datetime();
|
|
$end = verta::parse($data['end_time'])->datetime();
|
|
|
|
$data['start_time'] = $start;
|
|
$data['end_time'] = $end;
|
|
|
|
$flight->update($data);
|
|
|
|
return redirect()->route('admin.flights.index');
|
|
}
|
|
|
|
|
|
public function create()
|
|
{
|
|
$airports = Airport::all();
|
|
|
|
return view('admin.flights.create', compact('airports'));
|
|
}
|
|
|
|
public function destroy(Flight $flight)
|
|
{
|
|
$flight->delete();
|
|
|
|
return redirect()
|
|
->route('admin.flights.index')
|
|
->with('success', 'پرواز با موفقیت حذف شد.');
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
|
|
}
|
|
|
|
}
|