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