fix: update tour management
This commit is contained in:
@@ -5,14 +5,15 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\TourStoreRequest;
|
||||
use App\Models\Tour;
|
||||
use App\Models\TravelType;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TourController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$tour = Tour::latest()->paginate(10);
|
||||
return view('admin.tours.index', compact($tour));
|
||||
$tours = Tour::latest()->paginate(10);
|
||||
return view('admin.tours.index', compact('tours'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -23,25 +24,53 @@ class TourController extends Controller
|
||||
public function store(TourStoreRequest $request)
|
||||
{
|
||||
|
||||
Tour::create($request->validated());
|
||||
// Tour::create($request->validated());
|
||||
|
||||
|
||||
$tour = Tour::create($request->only([
|
||||
'travel_type_id', 'title', 'slug', 'description',
|
||||
'start_date', 'end_date', 'price', 'capacity', 'status'
|
||||
]));
|
||||
|
||||
$this->uploadImages($tour, $request->file('images'));
|
||||
return view('admin.tours.index')
|
||||
->with('success', 'تور با موفقیت ایجاد شد.');
|
||||
}
|
||||
|
||||
public function show(Tour $tour)
|
||||
{
|
||||
return view('admin.tours.show', compact('tour'));
|
||||
}
|
||||
|
||||
public function edit(Tour $tour)
|
||||
{
|
||||
return view('admin.tours.edit', compact('tour'));
|
||||
$travelTypes = TravelType::all();
|
||||
return view('admin.tours.edit', compact('tour', 'travelTypes'));
|
||||
}
|
||||
|
||||
public function update(TourStoreRequest $request, Tour $tour)
|
||||
{
|
||||
$tour->update($request->validated());
|
||||
|
||||
|
||||
// ذخیره فایل و گرفتن مسیر (بدون پسوند)
|
||||
$path = $request->file('image')->store('photos', 'public');
|
||||
|
||||
$extension = $request->file('image')->getClientOriginalExtension();
|
||||
|
||||
// ایجاد رکورد
|
||||
$tour->files()->create([
|
||||
'name' => $path,
|
||||
'extension' => $extension,
|
||||
'size' => $request->file('image')->getSize(),
|
||||
'original_name' => $request->file('image')->getClientOriginalName(),
|
||||
]);
|
||||
|
||||
|
||||
return redirect()->route('admin.tours.index')
|
||||
->with('success', 'تور با موفقیت بهروزرسانی شد.');
|
||||
}
|
||||
|
||||
public function destroy(Tour $tour)
|
||||
{
|
||||
$tour->delete();
|
||||
|
||||
@@ -74,6 +74,18 @@ class TourStoreRequest extends FormRequest
|
||||
'required',
|
||||
'integer',
|
||||
'min:0'],
|
||||
'images' =>
|
||||
[
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'images.*' =>
|
||||
[
|
||||
'image',
|
||||
'mimes:jpeg,png,jpg,webp',
|
||||
'max:2048'
|
||||
],
|
||||
|
||||
'status' =>
|
||||
[
|
||||
'nullable',
|
||||
|
||||
+18
-7
@@ -38,12 +38,17 @@ class Tour extends Model
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'travel_type_id' => 'int',
|
||||
'start_date' => 'datetime',
|
||||
'end_date' => 'datetime',
|
||||
'price' => 'float',
|
||||
'capacity' => 'int',
|
||||
'status' => 'int'
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'price' => 'decimal:2',
|
||||
'status' => 'integer',
|
||||
|
||||
// 'travel_type_id' => 'int',
|
||||
// 'start_date' => 'datetime',
|
||||
// 'end_date' => 'datetime',
|
||||
// 'price' => 'float',
|
||||
// 'capacity' => 'int',
|
||||
// 'status' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@@ -56,7 +61,8 @@ class Tour extends Model
|
||||
'end_date',
|
||||
'price',
|
||||
'capacity',
|
||||
'status'
|
||||
'status',
|
||||
'image',
|
||||
];
|
||||
|
||||
public function travelType()
|
||||
@@ -93,5 +99,10 @@ class Tour extends Model
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
public function getStatusLabelAttribute()
|
||||
{
|
||||
return $this->status == 1 ? 'فعال' : 'پیشنویس';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,62 @@
|
||||
<div>
|
||||
<!-- It always seems impossible until it is done. - Nelson Mandela -->
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container mt-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h4 class="mb-0">ثبت تور جدید</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route('admin.tours.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">عنوان تور</label>
|
||||
<input type="text" name="title"
|
||||
class="form-control @error('title') is-invalid @enderror"
|
||||
value="{{ old('title') }}">
|
||||
@error('title')
|
||||
<div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">توضیحات</label>
|
||||
<textarea name="description"
|
||||
class="form-control @error('description') is-invalid @enderror"
|
||||
rows="4">{{ old('description') }}</textarea>
|
||||
@error('description')
|
||||
<div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">قیمت</label>
|
||||
<input type="number" name="price"
|
||||
class="form-control @error('price') is-invalid @enderror"
|
||||
value="{{ old('price') }}">
|
||||
@error('price')
|
||||
<div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">تصویر تور</label>
|
||||
<input type="file" name="image"
|
||||
class="form-control @error('image') is-invalid @enderror">
|
||||
@error('image')
|
||||
<div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 d-flex justify-content-between">
|
||||
<a href="{{ route('admin.tours.index') }}" class="btn btn-secondary">انصراف</a>
|
||||
<button type="submit" class="btn btn-success">ذخیره تور</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
||||
@@ -1,3 +1,86 @@
|
||||
<div>
|
||||
<!-- It is not the man who has too little, but the man who craves more, that is poor. - Seneca -->
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h4>ویرایش تور: {{ $tour->title }}</h4>
|
||||
<a href="{{ route('admin.tours.index') }}" class="btn btn-secondary">بازگشت</a>
|
||||
</div>
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<form action="{{ route('admin.tours.update', $tour->id) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="row">
|
||||
<!-- عنوان -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">عنوان تور</label>
|
||||
<input type="text" name="title" class="form-control"
|
||||
value="{{ old('title', $tour->title) }}" required>
|
||||
</div>
|
||||
|
||||
<!-- نوع سفر -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">نوع سفر</label>
|
||||
<select name="travel_type_id" class="form-select">
|
||||
@foreach($travelTypes as $type)
|
||||
<option
|
||||
value="{{ $type->id }}" {{ $tour->travel_type_id == $type->id ? 'selected' : '' }}>
|
||||
{{ $type->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- قیمت -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">قیمت (تومان)</label>
|
||||
<input type="number" name="price" class="form-control"
|
||||
value="{{ old('price', $tour->price) }}">
|
||||
</div>
|
||||
|
||||
<!-- ظرفیت -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">ظرفیت</label>
|
||||
<input type="number" name="capacity" class="form-control"
|
||||
value="{{ old('capacity', $tour->capacity) }}">
|
||||
</div>
|
||||
|
||||
<!-- وضعیت -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">وضعیت</label>
|
||||
<select name="status" class="form-select">
|
||||
<option value="0" {{ $tour->status == 0 ? 'selected' : '' }}>پیشنویس</option>
|
||||
<option value="1" {{ $tour->status == 1 ? 'selected' : '' }}>فعال</option>
|
||||
<option value="2" {{ $tour->status == 2 ? 'selected' : '' }}>منتشر شده</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- توضیحات -->
|
||||
<div class="col-12 mb-3">
|
||||
<label class="form-label">توضیحات</label>
|
||||
<textarea name="description" class="form-control"
|
||||
rows="5">{{ old('description', $tour->description) }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-end">
|
||||
<button type="submit" class="btn btn-primary px-4">ذخیره تغییرات</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -1,3 +1,61 @@
|
||||
<div>
|
||||
<!-- Nothing worth having comes easy. - Theodore Roosevelt -->
|
||||
@extends('admin.layouts.app') {{-- فرض بر وجود لایوت ادمین --}}
|
||||
|
||||
@section('content')
|
||||
<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>
|
||||
|
||||
@if(session('success'))
|
||||
<div class="alert alert-success">{{ session('success') }}</div>
|
||||
@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>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<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>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -1,3 +1,80 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('title', 'جزئیات تور')
|
||||
|
||||
@section('content')
|
||||
{{-- هدر صفحه --}}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h3 class="mb-0">
|
||||
<i class="bi bi-airplane me-2"></i>
|
||||
جزئیات تور
|
||||
</h3>
|
||||
<div>
|
||||
<!-- Simplicity is an acquired taste. - Katharine Gerould -->
|
||||
<a href="{{ route('admin.tours.edit', $tour) }}" class="btn btn-warning">
|
||||
<i class="bi bi-pencil-square me-1"></i>ویرایش
|
||||
</a>
|
||||
<a href="{{ route('admin.tours.index') }}" class="btn btn-secondary">
|
||||
<i class="bi bi-arrow-right me-1"></i>بازگشت به لیست
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- کارت اطلاعات --}}
|
||||
<div class="card shadow-sm border-0">
|
||||
<div class="card-header bg-white py-3">
|
||||
<span class="fw-bold">{{ $tour->title }}</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-bordered table-striped align-middle mb-0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="bg-light" style="width: 200px;">عنوان</th>
|
||||
<td>{{ $tour->title }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">مبدا</th>
|
||||
<td>{{ $tour->origin }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">مقصد</th>
|
||||
<td>{{ $tour->destination }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">تاریخ شروع</th>
|
||||
<td>{{ \Carbon\Carbon::parse($tour->start_date)->format('Y/m/d') }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">تاریخ پایان</th>
|
||||
<td>{{ \Carbon\Carbon::parse($tour->end_date)->format('Y/m/d') }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">قیمت</th>
|
||||
<td>{{ number_format($tour->price) }} <small>تومان</small></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">ظرفیت</th>
|
||||
<td>{{ $tour->capacity }} <small>نفر</small></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">وضعیت</th>
|
||||
<td>
|
||||
@if($tour->status == 0)
|
||||
<span class="badge bg-danger">غیرفعال</span>
|
||||
@elseif($tour->status == 1)
|
||||
<span class="badge bg-warning text-dark">فعال / پیشنویس</span>
|
||||
@elseif($tour->status == 2)
|
||||
<span class="badge bg-success">منتشرشده</span>
|
||||
@else
|
||||
<span class="badge bg-secondary">نامشخص</span>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="bg-light">توضیحات</th>
|
||||
<td>{!! nl2br(e($tour->description)) !!}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user