PHPackages                             mahmudulhsn/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. mahmudulhsn/shopping-cart

ActiveLibrary[Framework](/categories/framework)

mahmudulhsn/shopping-cart
=========================

A simple shopping cart package for Laravel applications.

1.0.5(1y ago)010MITPHPPHP ^8.2 || ^8.3

Since Nov 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mahmudulhsn/shopping-cart)[ Packagist](https://packagist.org/packages/mahmudulhsn/shopping-cart)[ Docs](https://github.com/mahmudulhsn/shopping-cart)[ GitHub Sponsors](https://github.com/sponsors/mahmudulhsn)[ RSS](/packages/mahmudulhsn-shopping-cart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

Lara Simple Shopping Cart
-------------------------

[](#lara-simple-shopping-cart)

A simple shopping cart implementation for Laravel.

Installation
------------

[](#installation)

Install the package through [Composer](http://getcomposer.org/).

Run the Composer require command from the Terminal:

```
composer require mahmudulhsn/shopping-cart

```

Run this command for publishing the provider.

```
php artisan vendor:publish --provider="Mahmudulhsn\ShoppingCart\ShoppingCartServiceProvider"

```

Run this command for publishing the config. You can change the config according to you needs.(Optional)

```
php artisan vendor:publish --tag="shopping-cart-config"

```

You can add alias in the `config/app.php` or you can use this namespace given below (Optional).

```
'aliases' => [
        // Other aliases...
        'Cart' => Mahmudulhsn\ShoppingCart\Facades\CartFacade::class,
    ],
```

or

```
use Mahmudulhsn\ShoppingCart\Facades\CartFacade as Cart;

```

Overview
--------

[](#overview)

Look at one of the following topics to learn more about ShoppingCart

- [Usage](#usage)

Usage
-----

[](#usage)

The Lara Simple Shopping Cart gives you the following methods to use:

### Cart::add()

[](#cartadd)

Adding an item to the cart is really simple, you just use the `add()` method, which accepts a variety of parameters.

In its most basic form you can specify the id, name, quantity, price of the product you'd like to add to the cart.

```
Cart::add('293ad', 'Product 1', 1, 9.99);
```

As an optional fifth parameter you can pass extra info as an array.

```
Cart::add('293ad', 'Product 1', 1, 9.99, ['color' => 'Red', 'size' => 'XL']);
```

### Cart::update()

[](#cartupdate)

To update an item in the cart, you'll first need the rowId of the item. Next you can use the `update()` method to update it.

```
$rowId = 'd2ab10bd906390824d60c40d94093333';
Cart::update($rowId, ['quantity' => 5, 'price' => 500]);
```

You can update other info like this.

```
$rowId = 'd2ab10bd906390824d60c40d94093333';
Cart::update($rowId, ['id'=> '293ad', 'name' => 'Product one updated', 'quantity' => 5, 'price' => 500]);
```

You can also update extra info by passing the info as an array.

```
$rowId = 'd2ab10bd906390824d60c40d94093333';
Cart::update($rowId, ['id'=> '293ad', 'name' => 'Product one updated', 'quantity' => 5, 'price' => 500, 'extraInfo' => ['color' => 'Red', 'size' => 'XL']]);
```

### Cart::remove()

[](#cartremove)

To remove an item for the cart, you'll again need the rowId. This rowId you simply pass to the `remove()` method and it will remove the item from the cart.

```
$rowId = 'd2ab10bd906390824d60c40d94093333';

Cart::remove($rowId);
```

### Cart::get()

[](#cartget)

If you want to get an item from the cart using its rowId, you can simply call the `get()` method on the cart and pass it the rowId.

```
$rowId = 'd2ab10bd906390824d60c40d94093333';

Cart::get($rowId);
```

### Cart::content()

[](#cartcontent)

Of course you also want to get the carts content. This is where you'll use the `content` method. This method will return a Collection of CartItems which you can iterate over and show the content to your customers.

```
Cart::content();
```

### Cart::destroy()

[](#cartdestroy)

If you want to completely remove the content of a cart, you can call the destroy method on the cart. This will remove all CartItems from the cart for the current cart instance.

```
Cart::destroy();
```

### Cart::total()

[](#carttotal)

The `total()` method can be used to get the calculated total of all items in the cart, given there price and quantity.

```
Cart::total();
```

### Cart::subtotal()

[](#cartsubtotal)

The `subtotal()` method can be used to get the total of all items in the cart, minus the total amount of tax.

```
Cart::subtotal();
```

### Cart::applyDiscount()

[](#cartapplydiscount)

The `applyDiscount()` method can be used to get the total of all items in the cart. This will take two parameters first parameter will be flat amount or percentage, second parameter will be discount type that is `fix` or `percentage`. By default it will take `fix` as second parameter.

```
Cart::applyDiscount(500);
```

or

```
Cart::applyDiscount(500, 'fix');
```

For percentage discount, you have to pass `percentage` as second parameter and amount must be equal or less than 100.

```
Cart::applyDiscount(10, 'percentage');
```

### Cart::discount()

[](#cartdiscount)

The `discount()` method can be used to get the total amount of discount of all items.

```
Cart::discount(); //200
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

540d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.4

1.0.3PHP ^8.2 || ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a9dedfe0857c145b49fb8b9f9f6c744b5c7575eff52afeecd0d9c017646b764?d=identicon)[mahmudulhsn](/maintainers/mahmudulhsn)

---

Top Contributors

[![mahmudulhsn](https://avatars.githubusercontent.com/u/50780152?v=4)](https://github.com/mahmudulhsn "mahmudulhsn (13 commits)")

---

Tags

laravelcarte-commerceshopping cart

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[lukepolo/laracart

A simple cart for Laravel

583135.4k1](/packages/lukepolo-laracart)

PHPackages © 2026

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