1. Go to this page and download the library: Download ashraam/laravel-simple-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/ */
ashraam / laravel-simple-cart example snippets
use Ashraam\LaravelSimpleCart\Facades\Cart;
// Add an item to cart
Cart::add(
id: 'product-1',
name:'Product Name',
price: 29.99,
quantity:2,
options: ['size' => 'L'],
meta: ['image' => 'https://example.com/product-1.jpg', 'category' => 'T-shirt']
);
// Update quantity
Cart::update('item-id', 3);
// Remove item
Cart::remove('item-id');
// Clear cart
Cart::clear();
// Get cart contents
$items = Cart::content();
// Get cart total
$total = Cart::total();
// Get number of items in cart
$count = Cart::count();
// Check if item exists in cart
if (Cart::has('item-id')) {
// Item exists
}
// Get a specific item from cart
$itemId = md5($productId . serialize($options)); // Generate item ID
$item = Cart::get($itemId); // Returns the item or null if not found