php - Gloudemans cart not add
one text
I was working an ecommerce website and using gloudeman to make a cart in laravel but it is not adding to the cart this is my
<?php
namespace App\Http\Livewire;
use Cart;
use Gloudemans\Shoppingcart\Contracts\Buyable;
use App\Models\Product;
use Livewire\Component;
use Livewire\withPagination;
class ShopeComponent extends Component implements Buyable
{
public function store($product_id,$product_name,$product_price)
{
Cart::add($product_id,$product_name,1,$product_price)->associate('App\Models\Product');
session()->flash('success_message','Item added in cart');
return redirect()->route('product.cart');
}
use withPagination;
public function render()
{
$products = Product::paginate(12);
return view('livewire.shope-component',['products'=>$products])->layout('layouts.home');
}
}
and my view is thi I am using a tamplate and I was following a tutorial I have done Everything he have done
<div class="row">
<ul class="product-list grid-products equal-container">
@foreach($products as $product)
<li class="col-lg-4 col-md-6 col-sm-6 col-xs-6 ">
<div class="product product-style-3 equal-elem ">
<div class="product-thumnail">
<a href="{{route('product.details',['slug'=>$product->slug])}}" title="{{$product->name}}">
<figure><img src="{{asset('assets/images/products')}}/{{$product->image}}" alt="{{$product->name}}"></figure>
</a>
</div>
<div class="product-info">
<a href="{{route('product.details',['slug'=>$product->slug])}}" class="product-name"><span>{{$product->name}}</span></a>
<div class="wrap-price"><span class="product-price">${{$product->regular_price}}</span></div>
<a href="#" class="btn add-to-cart" wire:click.prevent="store({{$product->id}},'{{$product->name}}',{{$product->regular_price}})">Add To Cart</a>
</div>
</div>
</li>
@endforeach
</ul>
</div>
Source