119 lines
3.3 KiB
PHP
119 lines
3.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
use App\Http\Requests\FlightStoreRequest;
|
|
use App\Http\Requests\FlightUpdateRequest;
|
|
use App\Models\Flight;
|
|
use App\Models\TravelType;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FlightController extends Controller
|
|
{
|
|
/**
|
|
* نمایش لیست پروازها
|
|
*/
|
|
public function index()
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('view'), 403);
|
|
|
|
$flights = Flight::query()
|
|
->with('travelType')
|
|
->latest()
|
|
->when(request('q'), function ($query, $q) {
|
|
$query->where(function ($query) use ($q) {
|
|
$query->where('flight_number', 'like', "%{$q}%")
|
|
->orWhere('airline_name', 'like', "%{$q}%")
|
|
->orWhere('origin', 'like', "%{$q}%")
|
|
->orWhere('destination', 'like', "%{$q}%");
|
|
});
|
|
})
|
|
->when(request('status') !== null, function ($query) {
|
|
$query->where('status', request('status'));
|
|
})
|
|
->paginate(10)
|
|
->withQueryString();
|
|
|
|
$travelTypes = TravelType::where('status', 1)->get();
|
|
|
|
return view('admin.flights.index', compact('flights', 'travelTypes'));
|
|
}
|
|
|
|
/**
|
|
* نمایش فرم ایجاد پرواز
|
|
*/
|
|
public function create()
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('create'), 403);
|
|
|
|
$travelTypes = TravelType::where('status', 1)->get();
|
|
|
|
return view('admin.flights.create', compact('travelTypes'));
|
|
}
|
|
|
|
/**
|
|
* ذخیره پرواز جدید
|
|
*/
|
|
public function store(FlightStoreRequest $request)
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('create'), 403);
|
|
|
|
Flight::create($request->validated());
|
|
|
|
return redirect()->route('admin.flights.index')
|
|
->with('success', 'پرواز با موفقیت ثبت شد.');
|
|
}
|
|
|
|
/**
|
|
* نمایش جزئیات یک پرواز
|
|
*/
|
|
public function show(Flight $flight)
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('view'), 403);
|
|
|
|
return view('admin.flights.show', compact('flight'));
|
|
}
|
|
|
|
/**
|
|
* نمایش فرم ویرایش پرواز
|
|
*/
|
|
public function edit(Flight $flight)
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('update'), 403);
|
|
|
|
$travelTypes = TravelType::where('status', 1)->get();
|
|
|
|
return view('admin.flights.edit', compact('flight', 'travelTypes'));
|
|
}
|
|
|
|
/**
|
|
* بروزرسانی پرواز
|
|
*/
|
|
public function update(FlightUpdateRequest $request, Flight $flight)
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('update'), 403);
|
|
|
|
$flight->update($request->validated());
|
|
|
|
return redirect()->route('admin.flights.index')
|
|
->with('success', 'پرواز با موفقیت بهروزرسانی شد.');
|
|
}
|
|
|
|
/**
|
|
* حذف پرواز
|
|
*/
|
|
public function destroy(Flight $flight)
|
|
{
|
|
abort_unless(auth('admin')->user()?->canManageFlights('delete'), 403);
|
|
|
|
$flight->delete();
|
|
|
|
return redirect()->route('admin.flights.index')
|
|
->with('success', 'پرواز با موفقیت حذف شد.');
|
|
}
|
|
}
|