PHPackages                             bahaaalhagar/shoppingcart - 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. [Database &amp; ORM](/categories/database)
4. /
5. bahaaalhagar/shoppingcart

ActiveLibrary[Database &amp; ORM](/categories/database)

bahaaalhagar/shoppingcart
=========================

Laravel simple Shopping Cart package

0.1.1(6y ago)5126[1 PRs](https://github.com/BahaaAlhagar/ShoppingCart/pulls)MITPHPPHP ~5.6|~7.0

Since Jan 12Pushed 6y ago2 watchersCompare

[ Source](https://github.com/BahaaAlhagar/ShoppingCart)[ Packagist](https://packagist.org/packages/bahaaalhagar/shoppingcart)[ Docs](https://github.com/BahaaAlhagar/ShoppingCart)[ RSS](/packages/bahaaalhagar-shoppingcart/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

ShoppingCart
============

[](#shoppingcart)

[![Latest Version on Packagist](https://camo.githubusercontent.com/12a6e7e2e5f90ae1e1a82c08a636b16f8b9c7a3df3676d75cae168fa97cc607f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4261686161416c68616761722f53686f7070696e67436172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/BahaaAlhagar/ShoppingCart)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/17b72c8686c92d2e0f6869634377147c9bdb4b46596296b453b446a484de7486/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4261686161416c68616761722f53686f7070696e67436172742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/BahaaAlhagar/ShoppingCart)[![Coverage Status](https://camo.githubusercontent.com/e493adffeb61c5953229d1312da9d048fc4ccf75e5fc367e21096a59d66cf26a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f4261686161416c68616761722f53686f7070696e67436172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/BahaaAlhagar/ShoppingCart/code-structure)[![Quality Score](https://camo.githubusercontent.com/28fd83d6a3901c9c2e3ee59a44ba4fa07699b287d9731ba84d96e109c35450a6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4261686161416c68616761722f53686f7070696e67436172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/BahaaAlhagar/ShoppingCart)[![Total Downloads](https://camo.githubusercontent.com/b7a42ced8728f85721123d08dc2945c6a8cc36050bae332432e1fcbc165e203d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4261686161416c68616761722f53686f7070696e67436172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/BahaaAlhagar/ShoppingCart)

a Simple ShoppingCart impelementaion for Laravel.

Install
-------

[](#install)

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

```
	composer require BahaaAlhagar/ShoppingCart
```

If you're using Laravel 5.5, this is all there is to do. if you're using Laravel 5.4 or less version then you have the register the package service provider and the package alias in your app. open `config/app.php` file. Add a new line to the `providers` array:

```
	BahaaAlhagar\ShoppingCart\ShoppingCartServiceProvider::class,
```

And add a new line to the `aliases` array:

```
	'Cart' => BahaaAlhagar\ShoppingCart\Facades\Cart::class,
```

Usage
-----

[](#usage)

The ShoppingCart 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 product Model, quantity ($qty) you'd like to add to the cart. note that the Product model must have a price column.

```
Cart::add($productModel, $qty);
```

if you didnt specify the $qty the cart will assume its 1 item.

As an optional third parameter you can pass it options, so you can add multiple items with the same id, but with (for instance) a different size or color for example.

```
Cart::add($productModel, $qty, ['size' => 'large', 'color' => 'black']);
```

**The `add()` method will return CartItem array of the item you just added to the cart.**

### Cart::modify()

[](#cartmodify)

To modify an item in the cart, you'll first need the uinqueIndex of the item.

the uniqueIndex is the item offset in the cart Model items array.

Next you can use the `modify()` method to modify it.

If you simply want to modify the quantity, you'll pass the modify method the uinqueIndex and the new quantity:

```
$uinqueIndex = '20185a4530208f76b2ef3eb95307a021';

Cart::modify($uinqueIndex, 2); // Will modify the quantity
```

### Cart::reduceOneItem()

[](#cartreduceoneitem)

to reduce certain Cart item quantity by 1, you'll first need the uinqueIndex of the item.

then

```
$uinqueIndex = '20185a4530208f76b2ef3eb95307a021';

Cart::reduceOneItem($uinqueIndex); // will reduce item quantity by 1
```

### Cart::remove()

[](#cartremove)

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

```
$uniqueIndex = '20185a4530208f76b2ef3eb95307a021';

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

### Cart::getContent()

[](#cartgetcontent)

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

```
Cart::getContent();
```

### 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 the cart from Session.

```
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::count()

[](#cartcount)

If you want to know how many items there are in your cart, you can use the `count()` method. This method will return the total number of items in the cart. So if you've added 2 books and 1 shirt, it will return 3 items.

```
Cart::count();
```

Exceptions
----------

[](#exceptions)

The Cart package will throw exceptions if something goes wrong. This way it's easier to debug your code using the Cart package or to handle the error based on the type of exceptions. The Cart packages can throw the following exceptions:

ExceptionReason*CartIsEmptyException*When trying to modify or reduce a cart item and the cart already empty*InvalidUniqueIndexException*When the uniqueIndex that got passed doesn't exists in the cart*InvalidQuantityException*When you try to add negative or float quantity.Events
------

[](#events)

The cart also has events build in. There are five events available for you to listen for.

EventFiredParametercartItem.addedWhen an item was added to the cart.The `CartItem` that was added.cartItem.modifiedWhen an item in the cart was modified or reduced by 1.The `CartItem` that was modified.cartItem.removedWhen an item is removed from the cart.The `CartItem` that was removed.cart.destroyedWhen the content of a cart was destroyed.return the removed Cart Model.Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Bahaa Alhagar](https://github.com/https://github.com/BahaaAlhagar)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

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 ~298 days

Total

3

Last Release

2490d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25075512?v=4)[Bahaa Alhagar](/maintainers/BahaaAlhagar)[@BahaaAlhagar](https://github.com/BahaaAlhagar)

---

Top Contributors

[![BahaaAlhagar](https://avatars.githubusercontent.com/u/25075512?v=4)](https://github.com/BahaaAlhagar "BahaaAlhagar (31 commits)")

---

Tags

laravelpackagegithubSkeletonshoppingcartBahaaAlhagar

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bahaaalhagar-shoppingcart/health.svg)

```
[![Health](https://phpackages.com/badges/bahaaalhagar-shoppingcart/health.svg)](https://phpackages.com/packages/bahaaalhagar-shoppingcart)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[moonshine/moonshine

Laravel administration panel

1.3k239.9k76](/packages/moonshine-moonshine)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

4821.5k](/packages/erag-laravel-lang-sync-inertia)[laragear/populate

Populate your database with a supercharged, continuable seeder

8713.1k](/packages/laragear-populate)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)

PHPackages © 2026

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