diff --git a/app/Http/Controllers/admin/FlightController.php b/app/Http/Controllers/admin/FlightController.php index 223cf27..3a56067 100644 --- a/app/Http/Controllers/admin/FlightController.php +++ b/app/Http/Controllers/admin/FlightController.php @@ -4,6 +4,12 @@ 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 @@ -13,103 +19,100 @@ class FlightController extends Controller */ public function index() { - return 'Flights 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() { - return 'Flights 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(Request $request) + 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) + public function show(Flight $flight) { - return 'Flights show'; - } + abort_unless(auth('admin')->user()?->canManageFlights('view'), 403); + return view('admin.flights.show', compact('flight')); + } /** * نمایش فرم ویرایش پرواز */ - public function edit($flight) + public function edit(Flight $flight) { - return 'Flights edit'; - } + 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(Request $request, $flight) + 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) + public function destroy(Flight $flight) { - // + abort_unless(auth('admin')->user()?->canManageFlights('delete'), 403); + + $flight->delete(); + + return redirect()->route('admin.flights.index') + ->with('success', 'پرواز با موفقیت حذف شد.'); } } -// -//namespace App\Http\Controllers\Admin; -// -//use App\Http\Controllers\Controller; -//use Illuminate\Http\Request; -// -//class FlightController extends Controller -//{ -// public function index() -// { -// return 'Flights index'; -// } -// -// public function create() -// { -// return 'Flights create'; -// } -// -// public function store() -// { -// // -// } -// -// public function show($flight) -// { -// return 'Flights show'; -// } -// -// public function edit($flight) -// { -// return 'Flights edit'; -// } -// -// public function update($flight) -// { -// // -// } -// -// public function destroy($flight) -// { -// // -// } -//} diff --git a/app/Models/Flight.php b/app/Models/Flight.php index d8143ed..e2a0462 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -1,5 +1,6 @@ 'int', - 'departure_date' => 'datetime', - 'departure_time' => 'datetime', - 'arrival_date' => 'datetime', - 'arrival_time' => 'datetime', - 'price' => 'float', - 'capacity' => 'int', - 'status' => 'int' - ]; + protected $casts = [ + 'travel_type_id' => 'int', + 'departure_date' => 'date', + 'arrival_date' => 'date', + 'departure_time' => 'datetime', + 'arrival_time' => 'datetime', + 'price' => 'decimal:2', + 'capacity' => 'int', + 'status' => 'int', + ]; - protected $fillable = [ - 'travel_type_id', - 'flight_number', - 'airline_name', - 'origin', - 'destination', - 'departure_date', - 'departure_time', - 'arrival_date', - 'arrival_time', - 'duration', - 'price', - 'capacity', - 'status' - ]; + protected $fillable = [ + 'travel_type_id', + 'flight_number', + 'airline_name', + 'origin', + 'destination', + 'departure_date', + 'departure_time', + 'arrival_date', + 'arrival_time', + 'duration', + 'price', + 'capacity', + 'status', + ]; - public function tours() - { - return $this->belongsToMany(Tour::class, 'tour_flights') - ->withPivot('id') - ->withTimestamps(); - } + /* ------------------------- روابط (Relations) ------------------------- */ + + /** + * نوع سفر (داخلی/خارجی/چارتر) مرتبط با این پرواز + */ + public function travelType() + { + return $this->belongsTo(TravelType::class); + } + + /** + * تورهای مرتبط با این پرواز + */ + public function tours() + { + return $this->belongsToMany(Tour::class, 'tour_flights') + ->withPivot('id') + ->withTimestamps(); + } + + /* --------------------------- Helper ها ------------------------------ */ + + public function statusLabel(): string + { + return $this->status == 1 ? 'فعال' : 'غیرفعال'; + } + + public function isActive(): bool + { + return (int)$this->status === 1; + } + + /** + * اسکوپ برای پروازهای فعال + */ + public function scopeActive($query) + { + return $query->where('status', 1); + } + + public function getRouteKeyName(): string + { + return 'id'; + } } + +// +///** +// * Created by Reliese Model. +// */ +// +//namespace App\Models; +// +//use Carbon\Carbon; +//use Illuminate\Database\Eloquent\Collection; +//use Illuminate\Database\Eloquent\Model; +// +///** +// * Class Flight +// * +// * @property int $id +// * @property int $travel_type_id +// * @property string $flight_number +// * @property string $airline_name +// * @property string $origin +// * @property string $destination +// * @property Carbon $departure_date +// * @property Carbon $departure_time +// * @property Carbon $arrival_date +// * @property Carbon $arrival_time +// * @property string $duration +// * @property float $price +// * @property int $capacity +// * @property int $status +// * @property Carbon $created_at +// * @property Carbon $updated_at +// * +// * @property Collection|Tour[] $tours +// * +// * @package App\Models +// */ +//class Flight extends Model +//{ +// protected $table = 'flights'; +// public static $snakeAttributes = false; +// +// protected $casts = [ +// 'travel_type_id' => 'int', +// 'departure_date' => 'datetime', +// 'departure_time' => 'datetime', +// 'arrival_date' => 'datetime', +// 'arrival_time' => 'datetime', +// 'price' => 'float', +// 'capacity' => 'int', +// 'status' => 'int' +// ]; +// +// protected $fillable = [ +// 'travel_type_id', +// 'flight_number', +// 'airline_name', +// 'origin', +// 'destination', +// 'departure_date', +// 'departure_time', +// 'arrival_date', +// 'arrival_time', +// 'duration', +// 'price', +// 'capacity', +// 'status' +// ]; +// +// public function tours() +// { +// return $this->belongsToMany(Tour::class, 'tour_flights') +// ->withPivot('id') +// ->withTimestamps(); +// } +//} diff --git a/resources/views/admin/flights/create.blade.php b/resources/views/admin/flights/create.blade.php index d6d106d..7d4ea5b 100644 --- a/resources/views/admin/flights/create.blade.php +++ b/resources/views/admin/flights/create.blade.php @@ -1,3 +1,536 @@ -
+ اطلاعات کامل پرواز را وارد کنید. +
+ ++ + پرواز + {{ $flight->flight_number }} + + را ویرایش میکنید. + +
+ ++ لیست پروازهای ثبت شده در سیستم +
+ +| + # + | + ++ شماره پرواز + | + ++ نوع سفر + | + ++ ایرلاین + | + ++ مسیر + | + ++ تاریخ حرکت + | + ++ قیمت + | + ++ وضعیت + | + ++ عملیات + | + +
|---|---|---|---|---|---|---|---|---|
| + {{ $flight->id }} + | + + + {{-- شماره پرواز --}} ++ + + {{ $flight->flight_number }} + + + | + + + {{-- نوع سفر --}} ++ + @if($flight->travelType) + + + {{ $flight->travelType->title }} + + + @else + + + — + + + @endif + + | + + + {{-- ایرلاین --}} ++ {{ $flight->airline_name }} + | + + + {{-- مسیر --}} ++ + + {{ $flight->origin }} + + + + ← + + + + {{ $flight->destination }} + + + | + + + {{-- تاریخ حرکت --}} +
+
+ @if($flight->departure_date)
+
+
+
+ {{ $flight->departure_date
+ ->toJalali()
+ ->format('Y/m/d') }}
+
+
+
+ @else
+
+
+ —
+
+
+ @endif
+
+
+ @if($flight->departure_time)
+
+ + + + + {{ $flight->departure_time->format('H:i') }} + + + + @endif + + |
+
+
+ {{-- قیمت --}}
+ + + + + {{ number_format($flight->price) }} + + + + + تومان + + + | + + + {{-- وضعیت --}} ++ + @if((int) $flight->status === 1) + + + فعال + + + @else + + + غیرفعال + + + @endif + + | + + + {{-- عملیات --}} +
+
+
+
+ {{-- مشاهده --}}
+ @if(auth('admin')->user()?->canManageFlights('view'))
+
+
+
+
+
+ مشاهده
+
+
+
+ @endif
+
+
+ {{-- ویرایش --}}
+ @if(auth('admin')->user()?->canManageFlights('update'))
+
+
+
+
+
+ ویرایش
+
+
+
+ @endif
+
+
+ {{-- حذف --}}
+ @if(auth('admin')->user()?->canManageFlights('delete'))
+
+
+
+ @endif
+
+
+
+ |
+
+
|
+
+
+
+
+
+
+
+
+ پروازی برای نمایش وجود ندارد.
+
+
+ |
+
+ ||||||||