PHPackages                             malekfar/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. malekfar/laravel-shopping-cart

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

malekfar/laravel-shopping-cart
==============================

Shopping cart package for laravel

7.0.2(5y ago)02MITPHPPHP &gt;=7.2

Since Jun 27Pushed 4y agoCompare

[ Source](https://github.com/Malekfar/laravel-shopping-cart)[ Packagist](https://packagist.org/packages/malekfar/laravel-shopping-cart)[ RSS](/packages/malekfar-laravel-shopping-cart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (11)Used By (0)

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

[](#laravel-shopping-cart)

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

[![Packagist](https://camo.githubusercontent.com/ab64044e1e2b6386b6b72efcfee87a08e01a844bd5736c6b72df60e7e9ef4c57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d656c69686f76762f6c61726176656c2d73686f7070696e672d636172742e737667)](https://packagist.org/packages/melihovv/laravel-shopping-cart)[![Packagist](https://camo.githubusercontent.com/3ada64fe3959d54061220aa885cdfde4182ffef4a2cc6816bb3d22f51579a2f4/68747470733a2f2f706f7365722e707567782e6f72672f6d656c69686f76762f6c61726176656c2d73686f7070696e672d636172742f642f746f74616c2e737667)](https://packagist.org/packages/melihovv/laravel-shopping-cart)[![Packagist](https://camo.githubusercontent.com/528dd2abe9ae749996be4ed98c1ae7261d64bfeb12adc9ee20246196b5bf69dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d656c69686f76762f6c61726176656c2d73686f7070696e672d636172742e737667)](https://packagist.org/packages/melihovv/laravel-shopping-cart)

Install
-------

[](#install)

Install via composer

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

```

### Publish configuration file and migrations

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

```
php artisan vendor:publish --provider="Melihovv\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' => 'Melihovv\ShoppingCart\Facades\ShoppingCart',

```

or

```
use Melihovv\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' => \Melihovv\ShoppingCart\Repositories\ShoppingCartDatabaseRepository::class,
// or
'repository' => \Melihovv\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/melihovv)
- [All contributors](https://github.com/melihovv/laravel-shopping-cart/graphs/contributors)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% 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.

###  Release Activity

Cadence

Every ~133 days

Recently: every ~145 days

Total

10

Last Release

2046d ago

Major Versions

0.0.1 → 5.5.02017-08-30

5.8.0 → 6.02019-09-07

6.0 → 7.02020-03-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/99f19c7ca787c28d131a6231ef111624290854b87c00f4ae3f9243db02bd4d9e?d=identicon)[malekfar](/maintainers/malekfar)

---

Top Contributors

[![melihovv](https://avatars.githubusercontent.com/u/8608721?v=4)](https://github.com/melihovv "melihovv (54 commits)")[![Andrewearls](https://avatars.githubusercontent.com/u/18337951?v=4)](https://github.com/Andrewearls "Andrewearls (1 commits)")[![bitw](https://avatars.githubusercontent.com/u/662422?v=4)](https://github.com/bitw "bitw (1 commits)")[![Malekfar](https://avatars.githubusercontent.com/u/33530385?v=4)](https://github.com/Malekfar "Malekfar (1 commits)")

---

Tags

laravelcartshopping cart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1310.5k](/packages/wearepixel-laravel-cart)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[ultrono/laravelshoppingcart-1

Laravel 11 and above Shopping cart

1110.0k](/packages/ultrono-laravelshoppingcart-1)

PHPackages © 2026

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