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', 'نظر شما با موفقیت ثبت شد.');
|
||||
|
||||
Reference in New Issue
Block a user