feat: update tour controller and debug

This commit is contained in:
2026-08-18 14:27:40 +03:30
parent 91702f30cd
commit c98277c10b
2 changed files with 17 additions and 2 deletions
+11 -2
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Favorite;
use App\Models\Tour; use App\Models\Tour;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -33,7 +34,7 @@ class TourController extends Controller
'file', 'file',
]); ]);
$detail = $tour->tour_details->first(); $detail = $tour->tour_details->first();
$comments = $tour->comments()->latest()->get();
$nights = $detail $nights = $detail
? (int) round(Carbon::parse($detail?->start_date) ? (int) round(Carbon::parse($detail?->start_date)
->diffInDays(Carbon::parse($detail?->end_date))) ->diffInDays(Carbon::parse($detail?->end_date)))
@@ -45,7 +46,15 @@ class TourController extends Controller
$endTravel = verta($detail?->end_date)->format('Y-m-d'); $endTravel = verta($detail?->end_date)->format('Y-m-d');
$startDay = verta($detail?->start_date)->format('%A'); $startDay = verta($detail?->start_date)->format('%A');
$endDay = verta($detail?->end_date)->format('%A'); $endDay = verta($detail?->end_date)->format('%A');
$isFavorite = false;
if (auth()->check()) {
$isFavorite = Favorite::where('user_id', auth()->id())
->where('favoritable_id', $tour->id)
->where('favoritable_type', \App\Models\Tour::class)
->exists();
}
return view('tours.show', compact('tour' , 'startTime' , 'endTime' , 'startTravel' , return view('tours.show', compact('tour' , 'startTime' , 'endTime' , 'startTravel' ,
'endTravel' , 'startDay' , 'endDay' , 'nights')); 'endTravel' , 'startDay' , 'endDay' , 'nights' , 'isFavorite' , 'comments'));
} }
} }
+6
View File
@@ -78,4 +78,10 @@ class Tour extends Model
{ {
return $this->morphMany(Favorite::class, 'favoritable'); return $this->morphMany(Favorite::class, 'favoritable');
} }
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
} }