fix: update admin tour management

This commit is contained in:
2026-08-20 08:17:05 +03:30
parent ccee91fdc4
commit 66cc0d64ad
2 changed files with 401 additions and 48 deletions
+12 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Favorite;
use App\Models\Tour; use App\Models\Tour;
use App\Models\TravelType; use App\Models\TravelType;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -113,9 +114,19 @@ class TourController extends Controller
->limit(4) ->limit(4)
->get(); ->get();
$isFav = false;
if (auth()->check()) {
$isFav = Favorite::where('user_id', auth()->id())
->where('favoritable_type', Tour::class)
->where('favoritable_id', $tour->id)
->exists();
}
return view( return view(
'tours.show', 'tours.show',
compact('tour', 'relatedTours') compact('tour', 'relatedTours', 'isFav')
); );
} }
+389 -47
View File
@@ -1,61 +1,403 @@
@extends('admin.layouts.app') {{-- فرض بر وجود لایوت ادمین --}} @extends('admin.layouts.app')
@section('content') @section('content')
<div class="container mt-4"> <div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2>مدیریت تورها</h2> {{-- ============================= --}}
<a href="{{ route('admin.tours.create') }}" class="btn btn-primary">افزودن تور جدید</a> {{-- هدر صفحه --}}
{{-- ============================= --}}
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h2 class="mb-1">
مدیریت تورها
</h2>
<p class="text-muted mb-0">
لیست تورهای ثبت شده در سیستم
</p>
</div>
<a
href="{{ route('admin.tours.create') }}"
class="btn btn-primary"
>
<i class="fa fa-plus"></i>
افزودن تور جدید
</a>
</div> </div>
{{-- ============================= --}}
{{-- پیام موفقیت --}}
{{-- ============================= --}}
@if(session('success')) @if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
<div class="alert alert-success alert-dismissible fade show">
{{ session('success') }}
<button
type="button"
class="close"
data-dismiss="alert"
aria-label="Close"
>
<span>&times;</span>
</button>
</div>
@endif @endif
<div class="card shadow">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>تصویر</th>
<th>عنوان تور</th>
<th>قیمت (تومان)</th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
@forelse($tours as $tour)
<tr>
<td>
<img src="{{ asset('storage/' . ($tour->image ?? 'default.jpg')) }}" width="60" class="rounded">
</td>
<td>{{ $tour->title }}</td>
<td>{{ number_format($tour->price) }}</td>
<td>
<div class="btn-group" role="group">
<a href="{{ route('admin.tours.show', $tour->id) }}" class="btn btn-sm btn-info text-white">مشاهده</a>
<a href="{{ route('admin.tours.edit', $tour->id) }}" class="btn btn-sm btn-warning text-white">ویرایش</a>
<form action="{{ route('admin.tours.destroy', $tour->id) }}" method="POST" onsubmit="return confirm('آیا مطمئن هستید؟')"> {{-- ============================= --}}
@csrf {{-- خطاهای عمومی --}}
@method('DELETE') {{-- ============================= --}}
<button type="submit" class="btn btn-sm btn-danger">حذف</button>
</form> @if($errors->has('general'))
</div>
</td> <div class="alert alert-danger">
</tr>
@empty {{ $errors->first('general') }}
<tr>
<td colspan="4" class="text-center">هیچ توری یافت نشد.</td>
</tr>
@endforelse
</tbody>
</table>
{{-- بخش بسیار مهم برای آزمون: نمایش لینک‌های صفحه‌بندی --}}
<div class="d-flex justify-content-center mt-3">
{{ $tours->links() }}
</div>
</div> </div>
@endif
{{-- ============================= --}}
{{-- جدول تورها --}}
{{-- ============================= --}}
<div class="card shadow-sm">
<div class="card-header">
<div class="d-flex justify-content-between align-items-center">
<strong>
لیست تورها
</strong>
<span class="badge badge-primary">
{{ $tours->total() }}
تور
</span>
</div>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover table-bordered mb-0">
<thead class="thead-light">
<tr>
<th style="width: 80px;">
#
</th>
<th style="width: 100px;">
تصویر
</th>
<th>
عنوان تور
</th>
<th>
قیمت
</th>
<th>
تاریخ حرکت
</th>
<th>
وضعیت
</th>
<th style="width: 230px;">
عملیات
</th>
</tr>
</thead>
<tbody>
@forelse($tours as $tour)
<tr>
{{-- شماره --}}
<td>
{{ $tours->firstItem() + $loop->index }}
</td>
{{-- تصویر --}}
<td>
@if($tour->image)
<img
src="{{ asset('storage/' . $tour->image) }}"
alt="{{ $tour->title }}"
width="70"
height="60"
class="rounded"
style="object-fit: cover;"
>
@else
<img
src="{{ asset('images/no-image.jpg') }}"
alt="بدون تصویر"
width="70"
height="60"
class="rounded"
style="object-fit: cover;"
>
@endif
</td>
{{-- عنوان --}}
<td>
<strong>
{{ $tour->title }}
</strong>
@if($tour->slug)
<small class="d-block text-muted">
{{ $tour->slug }}
</small>
@endif
</td>
{{-- قیمت --}}
<td>
@if($tour->price)
<strong>
{{ number_format($tour->price) }}
</strong>
تومان
@else
<span class="text-muted">
تعیین نشده
</span>
@endif
</td>
{{-- تاریخ حرکت --}}
<td>
@if($tour->start_date)
{{ $tour->start_date }}
@else
<span class="text-muted">
—
</span>
@endif
</td>
{{-- وضعیت --}}
<td>
@if($tour->status == 2)
<span class="badge badge-success">
تایید شده
</span>
@elseif($tour->status == 1)
<span class="badge badge-warning">
در انتظار تایید
</span>
@elseif($tour->status == 3)
<span class="badge badge-danger">
رد شده
</span>
@else
<span class="badge badge-secondary">
نامشخص
</span>
@endif
</td>
{{-- عملیات --}}
<td>
<div class="btn-group">
{{-- مشاهده --}}
<a
href="{{ route('admin.tours.show', $tour->id) }}"
class="btn btn-sm btn-info text-white"
>
<i class="fa fa-eye"></i>
مشاهده
</a>
{{-- ویرایش --}}
<a
href="{{ route('admin.tours.edit', $tour->id) }}"
class="btn btn-sm btn-warning text-white"
>
<i class="fa fa-edit"></i>
ویرایش
</a>
{{-- حذف --}}
<form
action="{{ route('admin.tours.destroy', $tour->id) }}"
method="POST"
onsubmit="return confirm('آیا از حذف این تور مطمئن هستید؟')"
style="display: inline;"
>
@csrf
@method('DELETE')
<button
type="submit"
class="btn btn-sm btn-danger"
>
<i class="fa fa-trash"></i>
حذف
</button>
</form>
</div>
</td>
</tr>
@empty
<tr>
<td
colspan="7"
class="text-center py-5"
>
<div class="text-muted">
<i
class="fa fa-plane"
style="font-size: 40px;"
></i>
<p class="mt-3 mb-0">
هیچ توری یافت نشد.
</p>
</div>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
{{-- ============================= --}}
{{-- Pagination --}}
{{-- ============================= --}}
@if($tours->hasPages())
<div class="card-footer">
<div class="d-flex justify-content-center">
{{ $tours->links() }}
</div>
</div>
@endif
</div> </div>
</div> </div>
@endsection @endsection