60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Tour;
|
|
use Carbon\Carbon;
|
|
|
|
if (!function_exists('generateSortRouteParameter')) {
|
|
function generateSortRouteParameter(string $sortKey): array
|
|
{
|
|
|
|
return array_merge(request()->query(), ['sort' => $sortKey]);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('activeSort')) {
|
|
function activeSort(string $sortKey, string $default = ''): string
|
|
{
|
|
$currentSort = request()->query('sort', $default);
|
|
|
|
|
|
if ($currentSort === $sortKey) {
|
|
return 'bg-blue-500 text-white font-DanaMedium';
|
|
}
|
|
|
|
return 'text-gray-600 dark:text-gray-300 hover:text-blue-500';
|
|
}
|
|
}
|
|
if (!function_exists('tourDuration')) {
|
|
function tourDuration(Tour $tour): string
|
|
{
|
|
$departure = $tour->tourDepartures->first();
|
|
|
|
if (!$departure) {
|
|
return 'نامشخص';
|
|
}
|
|
|
|
$start = Carbon::parse($departure->start_date);
|
|
$end = Carbon::parse($departure->end_date);
|
|
|
|
$nights = $start->diffInDays($end);
|
|
$days = $nights + 1;
|
|
|
|
return "{$days} روز و {$nights} شب";
|
|
}
|
|
}
|
|
if (!function_exists('tourDateRange')) {
|
|
function tourDateRange(Tour $tour): string
|
|
{
|
|
$departure = $tour->tourDepartures->first();
|
|
|
|
if (!$departure) {
|
|
return 'تاریخ نامشخص';
|
|
}
|
|
|
|
$start = Verta::instance($departure->start_date);
|
|
$end = Verta::instance($departure->end_date);
|
|
|
|
return $start->format('Y/m/d') . ' - ' . $end->format('Y/m/d');
|
|
}
|
|
}
|