feat(tours): add tour listing with pagination and routers
This commit is contained in:
@@ -3,10 +3,27 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Tour;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TourController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$tours = Tour::with('tour_details')->latest()->paginate(6);
|
||||
|
||||
$tours->each(function ($tour) {
|
||||
$detail = $tour->tour_details->first();
|
||||
|
||||
$tour->nights = $detail
|
||||
? Carbon::parse($detail->start_date)->diffInDays(Carbon::parse($detail->end_date))
|
||||
: null;
|
||||
});
|
||||
|
||||
return view('tours.index', compact('tours'));
|
||||
}
|
||||
public function show(Tour $tour)
|
||||
{
|
||||
$tour->load([
|
||||
|
||||
Reference in New Issue
Block a user