Looking to hire Laravel developers? Try LaraJobs

laravel-shopping-cart maintained by ankurk91

Description
Shopping cart manager for Laravel
Author
Last update
2025/06/20 15:06 (dev-main)
License
Downloads
1 157

Comments
comments powered by Disqus

Shopping Cart for Laravel

Packagist GitHub-tag License Downloads GH-Actions codecov

Shopping cart manager for Laravel.

Installation

You can install the package via composer:

composer require "ankurk91/laravel-shopping-cart"

Usage

You can use Facade

<?php
use Ankurk91\LaravelShoppingCart\Facades\ShoppingCart;
use App\Models\Product;

$product = Product::find(1);
$quantity = request('quantity');
$attributes = [
    'image_url' => asset('image.webp'),
];
$item = ShoppingCart::add(
    $product, 
    $product->name,
    $product->unit_price,
    $quantity, 
    $attributes,
);

ShoppingCart::find(1);
ShoppingCart::update($product->id, 3);
ShoppingCart::all();
ShoppingCart::count();
ShoppingCart::has($product);
ShoppingCart::isEmpty();
ShoppingCart::subtotal();
ShoppingCart::remove($product->getKey());
ShoppingCart::clear();

Or you can locate it from container

<?php
use Ankurk91\LaravelShoppingCart;

$shoppingCart = app(ShoppingCartManager::class);
$shoppingCart->all();

Note The cart items will be stored in default session storage.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Security

If you discover any security issues, please email pro.ankurk1[at]gmail[dot]com instead of using the issue tracker.

Attribution

This package is highly inspired by overtrue/laravel-shopping-cart

License

The MIT License.