41 lines
920 B
PHP
41 lines
920 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use App\Enums\CommentStatus;
|
|
use App\Enums\TourStatus;
|
|
use App\Models\Tour;
|
|
|
|
|
|
class TourController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$tours = Tour::query()
|
|
->where('status', TourStatus::ENABLE)
|
|
->with('file')
|
|
->applySort()
|
|
->paginate()
|
|
->withQueryString();
|
|
|
|
return view('tours.index', compact('tours'));
|
|
}
|
|
|
|
public function show(Tour $tour)
|
|
{
|
|
abort_if($tour->status !== TourStatus::ENABLE->value, 404);
|
|
|
|
$tour->increment('views');
|
|
|
|
$tour->load([
|
|
'file',
|
|
'comments' => function ($query) {
|
|
$query->where('status', CommentStatus::APPROVED)
|
|
->with('user')
|
|
->orderByDesc('created_at');
|
|
},
|
|
]);
|
|
|
|
return view('tours.show', compact('tour'));
|
|
}
|
|
}
|