PHPackages                             renamepackage/laravel-shopping-cart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. renamepackage/laravel-shopping-cart

ActiveLibrary[Framework](/categories/framework)

renamepackage/laravel-shopping-cart
===================================

Shopping cart package for laravel

017PHP

Since Jan 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kaekoko/package)[ Packagist](https://packagist.org/packages/renamepackage/laravel-shopping-cart)[ RSS](/packages/renamepackage-laravel-shopping-cart/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Shopping Cart
=====================

[](#laravel-shopping-cart)

[![GitHub Workflow Status](https://github.com/Renamepackage/laravel-shopping-cart/workflows/Run%20tests/badge.svg)](https://github.com/Renamepackage/laravel-shopping-cart/actions)[![styleci](https://camo.githubusercontent.com/87c2f4e388450fc74f44e7c0372f3bb7ac6f202dfb75a0fbbe19c24f8861fa20/68747470733a2f2f7374796c6563692e696f2f7265706f732f39353435353937372f736869656c64)](https://styleci.io/repos/95455977)

[![Packagist](https://camo.githubusercontent.com/2d55f8fb42470269ff4ca6bdcc5af89f5662dfab0a463d9556eda533a31699eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f52656e616d657061636b6167652f6c61726176656c2d73686f7070696e672d636172742e737667)](https://packagist.org/packages/Renamepackage/laravel-shopping-cart)[![Packagist](https://camo.githubusercontent.com/0c5f135e780938192e3801b08aec1ab390851d864586bb44e6c7fa0285d74893/68747470733a2f2f706f7365722e707567782e6f72672f52656e616d657061636b6167652f6c61726176656c2d73686f7070696e672d636172742f642f746f74616c2e737667)](https://packagist.org/packages/Renamepackage/laravel-shopping-cart)[![Packagist](https://camo.githubusercontent.com/4d9638716b94d15f63adb29fbac7f0d78c17a0c32e70732808fe87772b1548c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f52656e616d657061636b6167652f6c61726176656c2d73686f7070696e672d636172742e737667)](https://packagist.org/packages/Renamepackage/laravel-shopping-cart)

Install
-------

[](#install)

Install via composer

```
composer require Renamepackage/laravel-shopping-cart

```

### Publish configuration file and migrations

[](#publish-configuration-file-and-migrations)

```
php artisan vendor:publish --provider="Renamepackage\ShoppingCart\ServiceProvider"

```

### Run migrations

[](#run-migrations)

```
php artisan migrate

```

Overview
--------

[](#overview)

- [Usage](#usage)
- [Instances](#instances)
- [Storage](#storage)
- [Coupons](#coupons)

Usage
-----

[](#usage)

Regiser facade in config/app.php

```
'Cart' => 'Renamepackage\ShoppingCart\Facades\ShoppingCart',

```

or

```
use Renamepackage\ShoppingCart\Facades\ShoppingCart as Cart;

```

in the below examples.

The shopping cart gives you the following methods to use:

### Cart::add()

[](#cartadd)

Add an item to the shopping cart.

```
$cartItem = Cart::add($id, $name, $price, $quantity);
$cartItem = Cart::add($id, $name, $price, $quantity, [
    'color' => 'white',
]);
```

### Cart::remove()

[](#cartremove)

Remove the item with the specified unique id from the shopping cart. Unique id is used to store items with the same `$id`, but different `$options`.

```
$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

Cart::remove($cartItem->getUniqueId())
```

### Cart::has()

[](#carthas)

Check if the shopping cart contains the item with the specified unique id.

```
$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

if (Cart::has($cartItem->getUniqueId())) {
    // Do smth.
}
```

### Cart::get()

[](#cartget)

Get an item in the shopping cart by its unique id.

```
$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

$cartItem = Cart::get($cartItem->getUniqueId());
```

### Cart::content()

[](#cartcontent)

Get all items in the shopping cart.

### Cart::clear()

[](#cartclear)

Clear the shopping cart.

### Cart::count()

[](#cartcount)

Return number of items in the shopping cart. This method does not summarize quantities of item. For example, there are 3 books and 1 iPhone in the shopping cart, so this method returns 2.

### Cart::getTotal()

[](#cartgettotal)

Return total price of all items in the shopping cart.

```
Cart::add(1, 'iPhone 7', 500, 1);
Cart::add(1, 'iPad Pro', 700, 2);
Cart::getTotal(); // return 1900
```

Instances
---------

[](#instances)

The package supports multiple instances of the cart. Some examples:

```
Cart::instance('shopping')->add('192ao12', 'Product 1', 100, 10);

// Store and get the content of the 'shopping' cart
Cart::store->content();

Cart::instance('wishlist')->add('sdjk922', 'Product 2', 50, 1, ['size' => 'medium']);

// Store and get the content of the 'wishlist' cart
Cart::store()->content();

// If you want to get the content of the 'shopping' cart again
Cart::instance('shopping')->restore()->content();
```

**The default cart instance is called `default`, so when you're not using instances,`Cart::content();` is the same as `Cart::instance('default')->content()`.**

### Cart::instance()

[](#cartinstance)

Set current instance name.

### Cart::currentInstance()

[](#cartcurrentinstance)

Get current instance name.

Storage
-------

[](#storage)

Currently there are two possible storage to persist shopping cart:

- Database
- Redis

You can choose one by specifying repository class name in config

```
// config/shopping-cart.php

'repository' => \Renamepackage\ShoppingCart\Repositories\ShoppingCartDatabaseRepository::class,
// or
'repository' => \Renamepackage\ShoppingCart\Repositories\ShoppingCartRedisRepository::class,
```

In order to use redis storage you also need to install `predis/predis` package.

### Cart::store()

[](#cartstore)

Persist current shopping cart instance to storage.

```
Cart::store($user->id);
Cart::instance('cart')->store($user->id);
Cart::instance('wishlist')->store($user->id);
```

### Cart::restore()

[](#cartrestore)

Restore shopping cart instance to storage.

```
Cart::restore($user->id);
Cart::instance('cart')->restore($user->id);
Cart::instance('wishlist')->restore($user->id);
```

### Cart::destroy()

[](#cartdestroy)

Remove shopping cart instance from storage.

```
Cart::destroy($user->id);
Cart::instance('cart')->destroy($user->id);
Cart::instance('wishlist')->destroy($user->id);
```

Coupons
-------

[](#coupons)

You can easily add discount coupons to shopping cart. Currently there are two types of coupons:

- FixedDiscountCoupon
- PercentDiscountCoupon

Related methods:

### Cart::addCoupon()

[](#cartaddcoupon)

Add coupon to cart.

```
Cart::addCoupon(new FixedDiscountCoupon($name, $discount));
Cart::addCoupon(new PercentDiscountCoupon($name, 0.1)); // 10% discount
```

### Cart::coupons()

[](#cartcoupons)

Returns all coupons.

### Cart::getTotalWithCoupons()

[](#cartgettotalwithcoupons)

Returns total price with applied coupons.

```
Cart::add(1, 'iPhone 7', 500, 1);
Cart::add(1, 'iPad Pro', 700, 2);
Cart::addCoupon(new FixedDiscountCoupon($name, 300));
Cart::getTotal(); // return 1900 - 300 = 1600
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alexander Melihov](https://github.com/Renamepackage)
- [All contributors](https://github.com/Renamepackage/laravel-shopping-cart/graphs/contributors)

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/534cb9de913f5aec8e2b36135a2d07629e7fe9056973fa0c046f5ddf520b46be?d=identicon)[kaekoko](/maintainers/kaekoko)

---

Top Contributors

[![kaekoko](https://avatars.githubusercontent.com/u/40235787?v=4)](https://github.com/kaekoko "kaekoko (1 commits)")

### Embed Badge

![Health badge](/badges/renamepackage-laravel-shopping-cart/health.svg)

```
[![Health](https://phpackages.com/badges/renamepackage-laravel-shopping-cart/health.svg)](https://phpackages.com/packages/renamepackage-laravel-shopping-cart)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
