1. Go to this page and download the library: Download sumonwd/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/ */
sumonwd / laravel-cart example snippets
use Sumonwd\Cart\Facades\Cart;
// add(id, name, price, quantity = 1, attributes = [], asNewItem = false)
$rowId = Cart::add(1, 'Solitaire Ring', 1500.00, 2, [
'size' => '7',
'image' => '/img/ring.png',
'slug' => 'solitaire-ring',
]);
// Adding the same id + attributes again increases the quantity.
// Pass asNewItem: true to always create a separate row.
Cart::update($rowId, 3); // new quantity (0 removes the row)
Cart::update($rowId, ['name' => 'New']); // or update fields
Cart::remove($rowId);
Cart::clear();
Cart::get($rowId); // array|null
Cart::has($rowId);
Cart::content(); // Collection keyed by rowId
Cart::count(); // total quantity
Cart::countDistinct(); // number of rows
Cart::isEmpty();
Cart::setShipping(15);
Cart::subtotal();
Cart::discount();
Cart::tax(); // uses config('cart.tax_rate') on subtotal - discount
Cart::shipping();
Cart::total();