1. Go to this page and download the library: Download masterix21/laravel-cart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
masterix21 / laravel-cart example snippets
$product = YourProductModel::first();
//
// Add a product to cart
$cartItem = Cart::add(label: $product->name, item: $product, price: $product->price, quantity: 1);
//
// Change the cart item quantity
Cart::set($cartItem, 2); // or
$cartItem->setQuantity(2);
//
// Increase the cart item quantity
Cart::increase($cartItem); // to increase of 1
Cart::increase($cartItem, 5); // to increase of 5
$cartItem->increase(); // to increase of 1
$cartItem->increase(5); // to increase of 5
//
// Decrease the cart item quantity, and if the
// quantity is zero, removes the item from the cart.
Cart::decrease($cartItem); // to decrease of 1
Cart::decrease($cartItem, 5); // to decrease of 5
$cartItem->decrease(); // to decrease of 1
$cartItem->decrease(5); // to decrease of 5
// Retrieve all cart items
$items = Cart::items();
// Clear the cart
Cart::clear();