I'm creating a wishlist where the user can save his own products and save them. What I want is that a user can't save a product more than one time. So, what I'm doing is, if the product_id exists in the DB, I don't want to save the new record.
This is my code, what am I doing wrong?
public function addWishlist(Wishlist $wishlist) {
$wishlist->user_id = request('user_id');
$wishlist->product_id = request('product_id');
if(DB::table('wishlists')->where('product_id' !== $wishlist->product_id)) {
$wishlist->save();
return redirect()->back();
}
}