feat: implement flights index and blade view for panel admin

This commit is contained in:
2026-08-20 13:31:51 +03:30
parent 8d0cd16384
commit 3e60fa13d3
5 changed files with 609 additions and 2 deletions
+10
View File
@@ -10,4 +10,14 @@ enum FlightStatus:int
case CANCELLED = 2;
case DRAFT = 3;
case DELAYED = 4;
public function label(): string
{
return match($this) {
self::AVAILABLE => 'در دسترس',
self::FULL => 'تکمیل ظرفیت',
self::CANCELLED => 'کنسل شده',
self::DRAFT => 'در انتظار',
self::DELAYED => 'با تاخیر',
};
}
}
@@ -3,9 +3,65 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Flight;
use Illuminate\Http\Request;
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()
{
}
public function store()
{
}
public function edit()
{
}
public function update()
{
}
public function destroy()
{
}
public function restore()
{
}
public function forceDelete()
{
}
}
+1 -1
View File
@@ -81,7 +81,7 @@ class Flight extends Model
{
switch ($sort) {
case 'popularity':
$query->withCount('bookings')->orderByDesc('bookings_count');
$query->orderByDesc('views_count');
break;
case 'lowest':
@@ -0,0 +1,264 @@
@extends('admin.layouts.app')
@section('breadcrumb')
<div>
<h1 class="page-title fw-medium fs-18 mb-2">لیست پروازها</h1>
<nav>
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item">
<a href="javascript:void(0);">پروازها</a>
</li>
<li class="breadcrumb-item active" aria-current="page">
لیست پروازها
</li>
</ol>
</nav>
</div>
@endsection
@section('content')
<div class="container-fluid pt-4">
@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="card-body p-3">
<form method="GET" action="{{ route('admin.flights.index') }}">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-3">
<div class="d-flex flex-wrap gap-2 project-list-main align-items-center">
<div class="d-flex">
<input class="form-control me-2"
type="search"
name="search"
placeholder="جست‌وجوی شماره پرواز"
value="{{ request('search') }}"
aria-label="جست‌وجو">
<button class="btn btn-light" type="submit">
جست‌وجو
</button>
</div>
<select class="form-control"
name="sort"
onchange="this.form.submit()">
<option value="">مرتب‌سازی بر اساس</option>
<option value="newest"
@selected(request()->missing('sort') || request('sort') === 'newest')>
جدیدترین
</option>
<option value="lowest"
@selected(request('sort') === 'lowest')>
کمترین قیمت
</option>
<option value="highest"
@selected(request('sort') === 'highest')>
بیشترین قیمت
</option>
<option value="popularity"
@selected(request('sort') === 'popularity')>
پر بازدیدترین
</option>
</select>
</div>
<div class="d-flex align-items-center gap-2">
<a href="{{ route('admin.flights.trash.index') }}"
class="btn btn-danger-light d-flex align-items-center">
<i class="ri-delete-bin-3-line me-1 fw-medium align-middle"></i>
سطل زباله
</a>
<a href="{{ route('admin.flights.create') }}"
class="btn btn-primary">
<i class="ri-add-line me-1 fw-medium align-middle"></i>
ایجاد پرواز
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="table-responsive">
<table class="table text-nowrap table-bordered align-middle">
<thead>
<tr>
<th>تصویر</th>
<th>شماره پرواز</th>
<th>ایرلاین</th>
<th>مبدأ</th>
<th>مقصد</th>
<th>زمان حرکت</th>
<th>قیمت</th>
<th>ظرفیت</th>
<th>وضعیت</th>
<th>بازدید</th>
<th>تاریخ ایجاد</th>
<th>اقدامات</th>
</tr>
</thead>
<tbody>
@forelse($flights as $flight)
<tr>
<td>
<span class="avatar avatar-md avatar-square bg-light">
@if($flight->coverImage?->file_id)
<img src="{{ getFileUrl($flight->coverImage->file_id) }}"
class="w-100 h-100"
alt="{{ $flight->flight_number }}">
@else
-
@endif
</span>
</td>
<td>
<span class="fw-medium">
{{ $flight->flight_number }}
</span>
</td>
<td>
{{ $flight->airline?->name ?? '-' }}
</td>
<td>
<div class="fw-medium">
{{ $flight->origin_airport?->city?->name ?? '-' }}
</div>
@if($flight->origin_airport?->name)
<small class="text-muted">
{{ $flight->origin_airport->name }}
</small>
@endif
</td>
<td>
<div class="fw-medium">
{{ $flight->airport?->city?->name ?? '-' }}
</div>
@if($flight->airport?->name)
<small class="text-muted">
{{ $flight->airport->name }}
</small>
@endif
</td>
<td>
@if($flight->departure_time)
{{ \Hekmatinasser\Verta\Verta::instance($flight->departure_time)->format('d F Y - H:i') }}
@else
-
@endif
</td>
<td>
{{ number_format($flight->price) }} تومان
</td>
<td>
<span class="badge bg-info-transparent">
{{ $flight->capacity }} نفر
</span>
</td>
<td>
@if($flight->status)
<span class="badge bg-success-transparent">
{{ $flight->status->label() }}
</span>
@else
-
@endif
</td>
<td>
{{ number_format($flight->views_count ?? 0) }}
</td>
<td>
@if($flight->created_at)
{{ \Hekmatinasser\Verta\Verta::instance($flight->created_at)->format('d F Y - H:i') }}
@else
-
@endif
</td>
<td>
<div class="hstack gap-2 fs-15">
<a href="{{ route('admin.flights.show', $flight->id) }}"
class="btn btn-info-light btn-icon btn-sm"
title="مشاهده">
<i class="ri-eye-line"></i>
</a>
<a href="{{ route('admin.flights.edit', $flight->id) }}"
class="btn btn-secondary-light btn-icon btn-sm"
title="ویرایش">
<i class="ti ti-pencil"></i>
</a>
<form action="{{ route('admin.flights.destroy', $flight->id) }}"
method="POST"
class="d-inline"
onsubmit="return confirm('از حذف این پرواز مطمئن هستید؟')">
@csrf
@method('DELETE')
<button type="submit"
class="btn btn-icon btn-sm btn-danger-light"
title="حذف">
<i class="ri-delete-bin-line"></i>
</button>
</form>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="12" class="text-center text-muted py-4">
هیچ پروازی یافت نشد.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-end mt-3">
{{ $flights->links() }}
</div>
</div>
@endsection
@@ -0,0 +1,277 @@
<?php $__env->startSection('breadcrumb'); ?>
<div>
<h1 class="page-title fw-medium fs-18 mb-2">لیست پروازها</h1>
<nav>
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item">
<a href="javascript:void(0);">پروازها</a>
</li>
<li class="breadcrumb-item active" aria-current="page">
لیست پروازها
</li>
</ol>
</nav>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="container-fluid pt-4">
<?php if(session('success')): ?>
<div class="alert alert-success">
<?php echo e(session('success')); ?>
</div>
<?php endif; ?>
<?php if(session('error')): ?>
<div class="alert alert-danger">
<?php echo e(session('error')); ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="card-body p-3">
<form method="GET" action="<?php echo e(route('admin.flights.index')); ?>">
<div class="d-flex align-items-center justify-content-between flex-wrap gap-3">
<div class="d-flex flex-wrap gap-2 project-list-main align-items-center">
<div class="d-flex">
<input class="form-control me-2"
type="search"
name="search"
placeholder="جست‌وجوی شماره پرواز"
value="<?php echo e(request('search')); ?>"
aria-label="جست‌وجو">
<button class="btn btn-light" type="submit">
جست‌وجو
</button>
</div>
<select class="form-control"
name="sort"
onchange="this.form.submit()">
<option value="">مرتب‌سازی بر اساس</option>
<option value="newest"
<?php if(request()->missing('sort') || request('sort') === 'newest'): echo 'selected'; endif; ?>>
جدیدترین
</option>
<option value="lowest"
<?php if(request('sort') === 'lowest'): echo 'selected'; endif; ?>>
کمترین قیمت
</option>
<option value="highest"
<?php if(request('sort') === 'highest'): echo 'selected'; endif; ?>>
بیشترین قیمت
</option>
<option value="popularity"
<?php if(request('sort') === 'popularity'): echo 'selected'; endif; ?>>
پر بازدیدترین
</option>
</select>
</div>
<div class="d-flex align-items-center gap-2">
<a href="<?php echo e(route('admin.flights.trash.index')); ?>"
class="btn btn-danger-light d-flex align-items-center">
<i class="ri-delete-bin-3-line me-1 fw-medium align-middle"></i>
سطل زباله
</a>
<a href="<?php echo e(route('admin.flights.create')); ?>"
class="btn btn-primary">
<i class="ri-add-line me-1 fw-medium align-middle"></i>
ایجاد پرواز
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card custom-card">
<div class="table-responsive">
<table class="table text-nowrap table-bordered align-middle">
<thead>
<tr>
<th>تصویر</th>
<th>شماره پرواز</th>
<th>ایرلاین</th>
<th>مبدأ</th>
<th>مقصد</th>
<th>زمان حرکت</th>
<th>قیمت</th>
<th>ظرفیت</th>
<th>وضعیت</th>
<th>بازدید</th>
<th>تاریخ ایجاد</th>
<th>اقدامات</th>
</tr>
</thead>
<tbody>
<?php $__empty_1 = true; $__currentLoopData = $flights; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $flight): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
<tr>
<td>
<span class="avatar avatar-md avatar-square bg-light">
<?php if($flight->coverImage?->file_id): ?>
<img src="<?php echo e(getFileUrl($flight->coverImage->file_id)); ?>"
class="w-100 h-100"
alt="<?php echo e($flight->flight_number); ?>">
<?php else: ?>
-
<?php endif; ?>
</span>
</td>
<td>
<span class="fw-medium">
<?php echo e($flight->flight_number); ?>
</span>
</td>
<td>
<?php echo e($flight->airline?->name ?? '-'); ?>
</td>
<td>
<div class="fw-medium">
<?php echo e($flight->origin_airport?->city?->name ?? '-'); ?>
</div>
<?php if($flight->origin_airport?->name): ?>
<small class="text-muted">
<?php echo e($flight->origin_airport->name); ?>
</small>
<?php endif; ?>
</td>
<td>
<div class="fw-medium">
<?php echo e($flight->airport?->city?->name ?? '-'); ?>
</div>
<?php if($flight->airport?->name): ?>
<small class="text-muted">
<?php echo e($flight->airport->name); ?>
</small>
<?php endif; ?>
</td>
<td>
<?php if($flight->departure_time): ?>
<?php echo e(\Hekmatinasser\Verta\Verta::instance($flight->departure_time)->format('d F Y - H:i')); ?>
<?php else: ?>
-
<?php endif; ?>
</td>
<td>
<?php echo e(number_format($flight->price)); ?> تومان
</td>
<td>
<span class="badge bg-info-transparent">
<?php echo e($flight->capacity); ?> نفر
</span>
</td>
<td>
<?php if($flight->status): ?>
<span class="badge bg-success-transparent">
<?php echo e($flight->status->label()); ?>
</span>
<?php else: ?>
-
<?php endif; ?>
</td>
<td>
<?php echo e(number_format($flight->views_count ?? 0)); ?>
</td>
<td>
<?php if($flight->created_at): ?>
<?php echo e(\Hekmatinasser\Verta\Verta::instance($flight->created_at)->format('d F Y - H:i')); ?>
<?php else: ?>
-
<?php endif; ?>
</td>
<td>
<div class="hstack gap-2 fs-15">
<a href="<?php echo e(route('admin.flights.show', $flight->id)); ?>"
class="btn btn-info-light btn-icon btn-sm"
title="مشاهده">
<i class="ri-eye-line"></i>
</a>
<a href="<?php echo e(route('admin.flights.edit', $flight->id)); ?>"
class="btn btn-secondary-light btn-icon btn-sm"
title="ویرایش">
<i class="ti ti-pencil"></i>
</a>
<form action="<?php echo e(route('admin.flights.destroy', $flight->id)); ?>"
method="POST"
class="d-inline"
onsubmit="return confirm('از حذف این پرواز مطمئن هستید؟')">
<?php echo csrf_field(); ?>
<?php echo method_field('DELETE'); ?>
<button type="submit"
class="btn btn-icon btn-sm btn-danger-light"
title="حذف">
<i class="ri-delete-bin-line"></i>
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
<tr>
<td colspan="12" class="text-center text-muted py-4">
هیچ پروازی یافت نشد.
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-end mt-3">
<?php echo e($flights->links()); ?>
</div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\ASUS\Desktop\airline-agency\resources\views/admin/flights/index.blade.php ENDPATH**/ ?>