Reputation: 3
public function AddWishlist($id)
{
$userid = Auth::id();
$check = DB::table('whishlists')
->where('user_id', $userid)
->where('whishlists', $id)
->first();
$data = ['user_id' => $userid, 'product_id' => $id];
if (Auth::check())
{
if ($check)
{
$notification = ['messege' => 'already added whisahlist', 'alert-type' => 'error'];
return redirect()->back()->with($notification);
}
else
{
DB::table('whishlists')->insert($data);
$notification = [
'messege' => 'Suucessafully added whisahlist',
'alert-type' => 'success'
];
return redirect()->back()->with($notification);
}
}
else
{
$notification = array(
'messege' => 'At first login your account',
'alert-type' => 'error'
);
return redirect()->back()->with($notification);
}
}
Problem
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'whishlists' in 'where clause' (SQL: select * from `whishlists` where `user_id` = 1 and `whishlists` = 37 limit 1)
Upvotes: 0
Views: 36
Reputation: 1192
the logic will be to change
->where('whishlists', $id)
with
->where('whishlist_id', $id)
if its not working, Please show us the table whishlists
Note:
if $id is the id of the wishlist, i think this line should be reviewed :
$data = ['user_id' => $userid, 'product_id' => $id];
because it set 'product_id' with the whishlist id
Upvotes: 1