feat: update tour controller and debug
This commit is contained in:
@@ -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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user