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([ 'tour_details', 'originAirport', 'destinationAirport', 'file', ]); $detail = $tour->tour_details->first(); $nights = $detail ? (int) round(Carbon::parse($detail?->start_date) ->diffInDays(Carbon::parse($detail?->end_date))) : null; $startTime = verta($detail?->start_date)->format('d-%B'); $endTime = verta($detail?->end_date)->format('d-%B'); $startTravel = verta($detail?->start_date)->format('Y-m-d'); $endTravel = verta($detail?->end_date)->format('Y-m-d'); $startDay = verta($detail?->start_date)->format('%A'); $endDay = verta($detail?->end_date)->format('%A'); return view('tours.show', compact('tour' , 'startTime' , 'endTime' , 'startTravel' , 'endTravel' , 'startDay' , 'endDay' , 'nights')); } }