In terminal excute the following command 1. composer require hardevine/shoppingcart Then in app.php in config folder write the following code in providers array Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class, and in aliases array 'Cart' => Gloudemans\Shoppingcart\Facades\Cart::class, 2. Now in terminal execute the following command php artisan vendor:publish --provider="Gloudemans\Shoppingcart\ShoppingcartServiceProvider" --tag="config" 3. Now in ShopComponent class file at head write the following use Cart; then in ShopComponent write the following function 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', 'Items added in Cart'); return redirect()->route('cart.index'); } 4. Now in shopcomponent blade file, in Add To Cart a link add the following code wire code <a aria-label="Add To Cart" class="action-btn hover-up" href="#" wire:click.prevent="store('{{$product->id}}', '{{$product->name}}', '{{$product->regular_price}}')"><i class="fi-rs-shopping-bag-add"></i></a> 5. Now in cart-component blade file in the table after <tbody> start write the following code @if (Cart::count()>0) <tr> <td class="image product-thumbnail"><img src="{{asset('assets/imgs/shop/product-1-2.jpg')}}" alt="#"> </td> <td class="product-des product-name"> <h5 class="product-name"><a href="product-details.html">J.Crew Mercantile Women's Short-Sleeve</a></h5> <p class="font-xs">Maboriosam in a tonto nesciung eget<br> distingy magndapibus </p> </td> <td class="price" data-title="Price"><span>$65.00 </span> </td> <td class="text-center" data-title="Stock"> <div class="detail-qty border radius m-auto"> <a href="#" class="qty-down"><i class="fi-rs-angle-small-down"></i></a> <span class="qty-val">1</span> <a href="#" class="qty-up"><i class="fi-rs-angle-small-up"></i></a> </div> </td> <td class="text-right" data-title="Cart"> <span>$65.00 </span> </td> <td class="action" data-title="Remove"><a href="#" class="text-muted"><i class="fi-rs-trash"></i></a></td> </tr> @else <p>No Item In Cart</p> @endif 6. Now use following items to show cart items @foreach (Cart::content() as $item) <tr> <td class="image product-thumbnail"><img src="{{asset('assets/imgs/shop/product-')}}{{$item->model->id}}-1.jpg" alt="#"></td> <td class="product-des product-name"> <h5 class="product-name"><a href="product-details.html">{{$item->model->name}}</a></h5> </td> <td class="price" data-title="Price"><span>${{$item->model->regular_price}} </span></td> <td class="text-center" data-title="Stock"> <div class="detail-qty border radius m-auto"> <a href="#" class="qty-down"><i class="fi-rs-angle-small-down"></i></a> <span class="qty-val">1</span> <a href="#" class="qty-up"><i class="fi-rs-angle-small-up"></i></a> </div> </td> <td class="text-right" data-title="Cart"> <span>${{$item->subtotal}} </span> </td> <td class="action" data-title="Remove"><a href="#" class="text-muted"><i class="fi-rs-trash"></i></a></td> </tr> @endforeach 7. Now in cart totals <div class="table-responsive"> <table class="table"> <tbody> <tr> <td class="cart_total_label">Cart Subtotal</td> <td class="cart_total_amount"><span class="font-lg fw-900 text-brand">${{Cart::subtotal()}}</span></td> </tr> <tr> <td class="cart_total_label">Tax</td> <td class="cart_total_amount"><span class="font-lg fw-900 text-brand">${{Cart::tax()}}</span></td> </tr> <tr> <td class="cart_total_label">Shipping</td> <td class="cart_total_amount"> <i class="ti-gift mr-5"></i> Free Shipping</td> </tr> <tr> <td class="cart_total_label">Total</td> <td class="cart_total_amount"><strong><span class="font-xl fw-900 text-brand">${{Cart::total()}}</span></strong></td> </tr> </tbody> </table> </div>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter