Files
hatame.andarza09/app/Http/Controllers/TourController.php
T
hatame 2f431971c0 git add .
git commit "Complete project development and finalize features"
2026-08-22 11:14:07 +03:30

38 lines
870 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Tour;
use Illuminate\Support\Facades\Cache;
class TourController extends Controller
{
public function index()
{
$newestTour = Tour::with('travelType')
->latest()
->paginate(3);
$tours = Tour::with('travelType')
->latest()
->paginate(2);
return view('tours.index', compact('tours', 'newestTour'));
}
public function show(Tour $tour)
{
$tour->load('travelType');
$tour->increment('views');
$cacheKey = 'tour_views:' . $tour->id . ':' . now()->format('Y-m-d');
Cache::put($cacheKey, Cache::get($cacheKey, 0) + 1, now()->addDays(15));
$comments = $tour->comments()
->latest()
->get();
return view('tours.show', compact('tour','comments'));
}
}