Files
kiarash-airline/app/Http/Controllers/TourController.php
T

45 lines
1.4 KiB
PHP

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