diff --git a/app/Http/Controllers/FlightController.php b/app/Http/Controllers/FlightController.php index 3ca5895..e168d56 100644 --- a/app/Http/Controllers/FlightController.php +++ b/app/Http/Controllers/FlightController.php @@ -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', 'نظر شما با موفقیت ثبت شد.'); diff --git a/app/Http/Controllers/TourController.php b/app/Http/Controllers/TourController.php index 26b88ef..72db2c9 100644 --- a/app/Http/Controllers/TourController.php +++ b/app/Http/Controllers/TourController.php @@ -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', 'نظر شما با موفقیت ثبت شد.'); diff --git a/resources/views/flights/partials/sidebar.blade.php b/resources/views/flights/partials/sidebar.blade.php index 5ba3422..16495bd 100644 --- a/resources/views/flights/partials/sidebar.blade.php +++ b/resources/views/flights/partials/sidebar.blade.php @@ -3,7 +3,7 @@

پرواز

- {{number_format($flight->price)}} تومان + {{number_format($flight->price)}} تومان
@@ -15,14 +15,14 @@
- - + +
@@ -30,26 +30,52 @@
- - + +
- - افزودن به علاقه مندی ها +
+
+ @auth +
+ @csrf + + +
+ @else + + + افزودن به علاقه‌مندی‌ها + + @endauth +
{{$flight->views_count}} مشاهده
diff --git a/resources/views/tours/partials/sidebar.blade.php b/resources/views/tours/partials/sidebar.blade.php index d72e07d..5e424d3 100644 --- a/resources/views/tours/partials/sidebar.blade.php +++ b/resources/views/tours/partials/sidebar.blade.php @@ -22,68 +22,72 @@
- - -
-
-
- -
-
-
-
- +
+ +
+
+
+
+ + +
+
+
+
+
+ +
+ +
- -
- - - @auth -
- @csrf - - -
- @else - - - افزودن به علاقه‌مندی‌ها - - @endauth -
- +
+ @auth +
+ @csrf + + +
+ @else + + + افزودن به علاقه‌مندی‌ها + + @endauth +
{{$tour->views_count}} مشاهده diff --git a/storage/framework/views/1a86b579c48f772630a544f2f581551d.php b/storage/framework/views/1a86b579c48f772630a544f2f581551d.php index 623bc96..91ee79a 100644 --- a/storage/framework/views/1a86b579c48f772630a544f2f581551d.php +++ b/storage/framework/views/1a86b579c48f772630a544f2f581551d.php @@ -58,32 +58,36 @@ اکنون ثبت کن - guard()->check()): ?> -
- - - -
- - - - افزودن به علاقه‌مندی‌ها - -
+
+ guard()->check()): ?> +
+ + + +
+ + + + افزودن به علاقه‌مندی‌ها + + +
views_count); ?> مشاهده diff --git a/storage/framework/views/b7c895492b08bbd895f1fc98bd9f45f7.php b/storage/framework/views/b7c895492b08bbd895f1fc98bd9f45f7.php index 934acd8..f1b8a89 100644 --- a/storage/framework/views/b7c895492b08bbd895f1fc98bd9f45f7.php +++ b/storage/framework/views/b7c895492b08bbd895f1fc98bd9f45f7.php @@ -45,11 +45,36 @@
- افزودن به علاقه مندی ها
+
+ guard()->check()): ?> +
+ + + +
+ + + + افزودن به علاقه‌مندی‌ها + + +
views_count); ?> مشاهده