This is the code for homeController remove public function delete_cart($id) { $data = Cart::find($id); $data->delete(); flash()->success('The product has been Deleted successfully'); return redirect()->back(); }
You forgot the 'remove button' tutorial in this vid. If you posted the tutorial in other video, please tell me which one or send the link. I really need it. Thank you so much.
Controller : public function delete_cart($id){ if(Auth::id()){ $user= Auth::user(); $userid = $user->id; $count = Cart ::where('user_id',$userid)->count(); $cart =Cart ::where('user_id',$userid)->get(); $productId = $id; // ID produk yang ingin dicari // Mencari produk dalam keranjang $cartItem = Cart::where('product_id', $productId)->first();
public function carts() { return $this->hasMany(Cart::class); } If u define relationship like this in User model you can do something like this $totalCarts = auth()?->user()?->carts()?->count();
Problem is your price data In this case value like 2000 But you guve 2,000 kama is the numarical value thats why is happened after changing the value you got the total amount
This is the code for homeController remove
public function delete_cart($id)
{
$data = Cart::find($id);
$data->delete();
flash()->success('The product has been Deleted successfully');
return redirect()->back();
}
You forgot the 'remove button' tutorial in this vid. If you posted the tutorial in other video, please tell me which one or send the link. I really need it. Thank you so much.
how did you make the remove in cart
Controller :
public function delete_cart($id){
if(Auth::id()){
$user= Auth::user();
$userid = $user->id;
$count = Cart ::where('user_id',$userid)->count();
$cart =Cart ::where('user_id',$userid)->get();
$productId = $id; // ID produk yang ingin dicari
// Mencari produk dalam keranjang
$cartItem = Cart::where('product_id', $productId)->first();
$cartItem->delete();
toastr()->timeOut(10000)->closeButton()->success('Product Deleted Successfully');
}
return redirect()->back();
}
if you are encountering an error on getting the value paste this : $value += (int)$cart->product->price;
Undefined variable $value when you put the variable outside of the foreach.
public function carts()
{
return $this->hasMany(Cart::class);
} If u define relationship like this in User model you can do something like this
$totalCarts = auth()?->user()?->carts()?->count();
How to remove in cart?
How to stop adding the same products in to cart twice
This is how you guy get the remove button
Product Title
Price
Image
Remove
@foreach ($cart as $cart)
{{$cart->product->title}}
{{$cart->product->price}}
Remove
@endforeach
Give tha review and ratings for tha product
remove?
Why didn't you address the amount?
We can get prices using the product_id
It would be good if the number of products to buy was added to the cart.
next video
A non-numeric value encountered
Problem is your price data
In this case value like 2000
But you guve 2,000 kama is the numarical value thats why is happened after changing the value you got the total amount