feat: implement user favorites and fix toggle functionality
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Enums\CommentStatus;
|
||||
use App\Enums\Flight\FlightStatus;
|
||||
use App\Http\Requests\Flight\FlightCommentStoreRequest;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Favorite;
|
||||
use App\Models\Flight;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -33,7 +34,16 @@ class FlightController extends Controller
|
||||
{
|
||||
$title = 'جزئیات پرواز';
|
||||
$flight->increment('views_count');
|
||||
return view('flights.show' , compact('title' , 'flight'));
|
||||
|
||||
$isFavorite = false;
|
||||
|
||||
if (auth()->check()) {
|
||||
$isFavorite = Favorite::where('user_id', auth()->id())
|
||||
->where('flight_id', $flight->id)
|
||||
->exists();
|
||||
|
||||
}
|
||||
return view('flights.show', compact('title', 'flight', 'isFavorite'));
|
||||
}
|
||||
|
||||
public function commentStore(FlightCommentStoreRequest $request, Flight $flight)
|
||||
@@ -41,13 +51,13 @@ class FlightController extends Controller
|
||||
|
||||
try {
|
||||
Comment::create([
|
||||
'flight_id' => $flight->id,
|
||||
'user_id' => auth()->id(),
|
||||
'parent_id' => $request->parent_id,
|
||||
'guest_name' => auth()->check() ? null : $request->guest_name,
|
||||
'flight_id' => $flight->id,
|
||||
'user_id' => auth()->id(),
|
||||
'parent_id' => $request->parent_id,
|
||||
'guest_name' => auth()->check() ? null : $request->guest_name,
|
||||
'guest_email' => auth()->check() ? null : $request->guest_email,
|
||||
'content' => $request->content,
|
||||
'status' => CommentStatus::PENDING,
|
||||
'content' => $request->content,
|
||||
'status' => CommentStatus::PENDING,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Enums\CommentStatus;
|
||||
use App\Http\Requests\Tour\TourCommentStoreRequest;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Favorite;
|
||||
use App\Models\Tour;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -30,7 +31,7 @@ class TourController extends Controller
|
||||
|
||||
public function show(Tour $tour)
|
||||
{
|
||||
$title= 'جزئیات تور';
|
||||
$title = 'جزئیات تور';
|
||||
$tour->load([
|
||||
'file',
|
||||
'originCity',
|
||||
@@ -46,26 +47,26 @@ class TourController extends Controller
|
||||
$isFavorite = false;
|
||||
|
||||
if (auth()->check()) {
|
||||
$isFavorite = auth()->user()
|
||||
->favoriteTours()
|
||||
->where('tours.id', $tour->id)
|
||||
$isFavorite = Favorite::where('user_id', auth()->id())
|
||||
->where('tour_id', $tour->id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
return view('tours.show', compact('title' , 'tour'));
|
||||
return view('tours.show', compact('title', 'tour', 'isFavorite'));
|
||||
}
|
||||
|
||||
public function commentStore(TourCommentStoreRequest $request, Tour $tour)
|
||||
{
|
||||
|
||||
try {
|
||||
Comment::create([
|
||||
'tour_id' => $tour->id,
|
||||
'user_id' => auth()->id(),
|
||||
'parent_id' => $request->parent_id,
|
||||
'guest_name' => auth()->check() ? null : $request->guest_name,
|
||||
'tour_id' => $tour->id,
|
||||
'user_id' => auth()->id(),
|
||||
'parent_id' => $request->parent_id,
|
||||
'guest_name' => auth()->check() ? null : $request->guest_name,
|
||||
'guest_email' => auth()->check() ? null : $request->guest_email,
|
||||
'content' => $request->content,
|
||||
'status' => CommentStatus::PENDING,
|
||||
'content' => $request->content,
|
||||
'status' => CommentStatus::PENDING,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="listing-price">
|
||||
<h4 class="listing-price-tag">پرواز</h4>
|
||||
<div class="listing-price-amount">
|
||||
<span> {{number_format($flight->price)}} تومان</span>
|
||||
<span> {{number_format($flight->price)}} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="search-form">
|
||||
@@ -15,14 +15,14 @@
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
<div class="search-form-date">
|
||||
<label for="departure_date">تاریخ رفت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="departure_date"
|
||||
class="form-control"
|
||||
value="{{ verta($flight->departure_time)->format('Y/m/d - H:i') }}"
|
||||
disabled
|
||||
>
|
||||
<label for="departure_date">تاریخ رفت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="departure_date"
|
||||
class="form-control"
|
||||
value="{{ verta($flight->departure_time)->format('Y/m/d - H:i') }}"
|
||||
disabled
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -30,26 +30,52 @@
|
||||
<div class="form-group">
|
||||
<div class="search-form-date">
|
||||
<div class="search-form-return">
|
||||
<label for="return_date">تاریخ برگشت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="return_date"
|
||||
class="form-control"
|
||||
value="{{ $flight->arrival_time }}"
|
||||
disabled
|
||||
>
|
||||
<label for="return_date">تاریخ برگشت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="return_date"
|
||||
class="form-control"
|
||||
value="{{ $flight->arrival_time }}"
|
||||
disabled
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listing-side-btn">
|
||||
<button type="submit" class="theme-btn"><span class="far fa-shopping-bag"></span>اکنون ثبت کن</button>
|
||||
<a href="#" class="border-btn"><i class="far fa-heart"></i> افزودن به علاقه مندی ها</a>
|
||||
<button type="submit" class="theme-btn"><span class="far fa-shopping-bag"></span>اکنون ثبت کن
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="listing-side-btn mt-2">
|
||||
@auth
|
||||
<form action="{{ route('accounts.favorites.flight.toggle', ['flight' => $flight->id]) }}"
|
||||
method="POST"
|
||||
class="favorite-form">
|
||||
@csrf
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
@if ($isFavorite)
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
@else
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<a href="{{ route('auth.login.index') }}"
|
||||
class="border-btn"
|
||||
title="برای افزودن به علاقهمندیها وارد شوید">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
@endauth
|
||||
</div>
|
||||
<div class="listing-side-share">
|
||||
<span><i class="far fa-eye"></i> {{$flight->views_count}} مشاهده</span>
|
||||
</div>
|
||||
|
||||
@@ -22,68 +22,72 @@
|
||||
<div class="form-group">
|
||||
<div class="search-form-date">
|
||||
<div class="search-form-return">
|
||||
<label for="departure_date">زمان رفت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="departure_date"
|
||||
class="form-control"
|
||||
value="{{ $departure && $departure->start_date ? verta($departure->start_date)->format('Y/m/d - H:i') : 'نامشخص' }}"
|
||||
disabled
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
<div class="search-form-date">
|
||||
<div class="search-form-return">
|
||||
<label for="return_date">تاریخ برگشت</label>
|
||||
<label for="departure_date">زمان رفت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="return_date"
|
||||
id="departure_date"
|
||||
class="form-control"
|
||||
value="{{ $departure && $departure->end_date ? verta($departure->end_date)->format('Y/m/d - H:i') : 'نامشخص' }}"
|
||||
value="{{ $departure && $departure->start_date ? verta($departure->start_date)->format('Y/m/d - H:i') : 'نامشخص' }}"
|
||||
disabled
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
<div class="search-form-date">
|
||||
<div class="search-form-return">
|
||||
<label for="return_date">تاریخ برگشت</label>
|
||||
<input
|
||||
type="text"
|
||||
id="return_date"
|
||||
class="form-control"
|
||||
value="{{ $departure && $departure->end_date ? verta($departure->end_date)->format('Y/m/d - H:i') : 'نامشخص' }}"
|
||||
disabled
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="listing-side-btn">
|
||||
<button type="submit" class="theme-btn">
|
||||
<span class="far fa-shopping-bag"></span>
|
||||
اکنون ثبت کن
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="listing-side-btn">
|
||||
<button type="submit" class="theme-btn">
|
||||
<span class="far fa-shopping-bag"></span>
|
||||
اکنون ثبت کن
|
||||
</button>
|
||||
|
||||
@auth
|
||||
<form action="{{ route('accounts.favorites.tour.toggle', ['tour' => $tour->id]) }}"
|
||||
method="POST"
|
||||
class="d-inline">
|
||||
@csrf
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
@if ($isFavorite)
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
@else
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<a href="{{ route('auth.login.index') }}" class="border-btn">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
@endauth
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="listing-side-btn mt-2">
|
||||
@auth
|
||||
<form action="{{ route('accounts.favorites.tour.toggle', ['tour' => $tour->id]) }}"
|
||||
method="POST"
|
||||
class="favorite-form">
|
||||
@csrf
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
@if ($isFavorite)
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
@else
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<a href="{{ route('auth.login.index') }}"
|
||||
class="border-btn"
|
||||
title="برای افزودن به علاقهمندیها وارد شوید">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
@endauth
|
||||
</div>
|
||||
|
||||
<div class="listing-side-share">
|
||||
<span><i class="far fa-eye"></i> {{$tour->views_count}} مشاهده</span>
|
||||
|
||||
@@ -58,32 +58,36 @@
|
||||
اکنون ثبت کن
|
||||
</button>
|
||||
|
||||
<?php if(auth()->guard()->check()): ?>
|
||||
<form action="<?php echo e(route('accounts.favorites.tour.toggle', ['tour' => $tour->id])); ?>"
|
||||
method="POST"
|
||||
class="d-inline">
|
||||
<?php echo csrf_field(); ?>
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
<?php if($isFavorite): ?>
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
<?php else: ?>
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo e(route('auth.login.index')); ?>" class="border-btn">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="listing-side-btn mt-2">
|
||||
<?php if(auth()->guard()->check()): ?>
|
||||
<form action="<?php echo e(route('accounts.favorites.tour.toggle', ['tour' => $tour->id])); ?>"
|
||||
method="POST"
|
||||
class="favorite-form">
|
||||
<?php echo csrf_field(); ?>
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
<?php if($isFavorite): ?>
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
<?php else: ?>
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo e(route('auth.login.index')); ?>"
|
||||
class="border-btn"
|
||||
title="برای افزودن به علاقهمندیها وارد شوید">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="listing-side-share">
|
||||
<span><i class="far fa-eye"></i> <?php echo e($tour->views_count); ?> مشاهده</span>
|
||||
|
||||
@@ -45,11 +45,36 @@
|
||||
</div>
|
||||
<div class="listing-side-btn">
|
||||
<button type="submit" class="theme-btn"><span class="far fa-shopping-bag"></span>اکنون ثبت کن</button>
|
||||
<a href="#" class="border-btn"><i class="far fa-heart"></i> افزودن به علاقه مندی ها</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="listing-side-btn mt-2">
|
||||
<?php if(auth()->guard()->check()): ?>
|
||||
<form action="<?php echo e(route('accounts.favorites.flight.toggle', ['flight' => $flight->id])); ?>"
|
||||
method="POST"
|
||||
class="favorite-form">
|
||||
<?php echo csrf_field(); ?>
|
||||
|
||||
<button type="submit" class="border-btn border-0">
|
||||
<?php if($isFavorite): ?>
|
||||
<i class="fas fa-heart"></i>
|
||||
حذف از علاقهمندیها
|
||||
<?php else: ?>
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo e(route('auth.login.index')); ?>"
|
||||
class="border-btn"
|
||||
title="برای افزودن به علاقهمندیها وارد شوید">
|
||||
<i class="far fa-heart"></i>
|
||||
افزودن به علاقهمندیها
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="listing-side-share">
|
||||
<span><i class="far fa-eye"></i> <?php echo e($flight->views_count); ?> مشاهده</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user