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

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

mohammad-alavi/laravel-shoppingcart
===================================

A Shopping Cart Implementation for Laravel

v0.1.2(5y ago)1296[1 PRs](https://github.com/Mohammad-Alavi/laravel-shoppingcart/pulls)1MITPHPPHP ^7.4|^8.0

Since Mar 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Mohammad-Alavi/laravel-shoppingcart)[ Packagist](https://packagist.org/packages/mohammad-alavi/laravel-shoppingcart)[ RSS](/packages/mohammad-alavi-laravel-shoppingcart/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (5)Used By (1)

laravel-shoppingcart
====================

[](#laravel-shoppingcart)

A Shopping Cart Implementation for Laravel.

Based on [johannesschobel](https://github.com/johannesschobel) [laravel-shoppingcart](https://github.com/johannesschobel/laravel-shoppingcart)

Installation
============

[](#installation)

Install the package through Composer.

```
composer require mohammadalavi/laravel-shoppingcart
```

Then, you simply add the provided `migration` file using the following command:

```
php artisan vendor:publish --provider="MohammadAlavi\ShoppingCart\ShoppingCartServiceProvider" --tag="migrations"
```

and then you migrate your database using

```
php artisan db:migrate
```

If you want, you can overwrite the basic configuration of this package using the following command:

```
php artisan vendor:publish --provider="MohammadAlavi\ShoppingCart\ShoppingCartServiceProvider" --tag="config"
```

This will copy the `shoppingcart` configuration file to your `config` folder. Using this file, you can customize the various parameters of the package. Currently, not many are available, however, I will be adding more and more ;)

Usage
=====

[](#usage)

The `ShoppingCart` Facade provides some neat methods to deal with the shopping cart in general. These methods are:

LOAD a ShoppingCart from the database
-------------------------------------

[](#load-a-shoppingcart-from-the-database)

```
ShoppingCart::load($identifier, $name = null);
```

Load the cart with the `identifier` and `name` from the database. If no `name` is provided, the default name `default`will be used. If no cart exists, an empty cart will be returned. This cart remains temporary as long as no items are stored.

CLEAR a ShoppingCart
--------------------

[](#clear-a-shoppingcart)

```
ShoppingCart::clear();
```

Removes the current instance of the cart from the database.

ADD Items to the Cart
---------------------

[](#add-items-to-the-cart)

```
ShoppingCart::addItem(
   $id,
   $name = null,
   $type = null,
   $qty = 1,
   Money $price = null,
   $uri = null,
   array $options = []
);
```

This method allows for adding items to the cart. The basic usage allows you to directly specify the item you want to set. For example

```
ShoppingCart::addItem(
   '1234',
   'Basic T-Shirt',
   'products',
   10,
   new Money(999, new Currency('EUR')), // note the value is added in cents!
   '/products/1234',
   ['size' => 'large', 'color' => 'black']
);
```

would add 10 "Basic T-Shirts", each costs 9.99 EUR to the cart. The customer has specified a color and size.

You may, however, add the `Buyable` interface to your products in order to simplify this process. This will require you to implement additional methods on the model (you can add the `CanBePurchased` Trait in order to make a "best guess").

This would allow you to just add a specific product:

```
$product = Product::find(1234); // remember, Product must implement the Buyable interface!
ShoppingCart::addBuyable(
   $product,
   10,
   ['size' => 'large', 'color' => 'black']
);
```

would result in the same cart as above. However, the `id`, `name`, `price` and `uri` are directly taken from the model!

REMOVE Items from the Cart
--------------------------

[](#remove-items-from-the-cart)

```
ShoppingCart::removeItem($row)
```

To remove an item from the shopping cart you need to have its `rowId`. This `rowId` can be obtained, for example, via the `ShoppingCart::load()` or `ShoppingCart::getContent()` method.

```
$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::removeItem($rowId);
```

UPDATE Items in the Cart
------------------------

[](#update-items-in-the-cart)

```
ShoppingCart::updateItem($row, $qty = 1, array $options = [])
```

allows you to update a given row in the cart. This `rowId` can be obtained, for example, via the `ShoppingCart::load()` or `ShoppingCart::getContent()` method.

```
$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::updateItem($rowId, 1, ['color' => 'red']);
```

would update the quantity and options of the item (e.g., the product to be purchased shall be 'red' instead of 'black').

Items / Price / Taxes
---------------------

[](#items--price--taxes)

The Cart also provides methods to

- get the amount of items in the cart =&gt; `getItemCount()`
- get the content of the cart. This returns all items in the cart =&gt; `getContent()`
- get the value of the current cart
    - get the taxes of the cart =&gt; `getTaxes()`
    - get total (value including taxes) =&gt; `getTotal()`
    - get subtotal (value without taxes) =&gt; `getSubTotal()`
- get the "associated" `Buyable` model =&gt; `resolveModel()`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

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

Total

3

Last Release

1876d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e05ce3549156452319c5fdfc014b5eb441e3a6148f1f4957fb863026ecc6f8a0?d=identicon)[mohammad-alavi](/maintainers/mohammad-alavi)

---

Top Contributors

[![Mohammad-Alavi](https://avatars.githubusercontent.com/u/24431504?v=4)](https://github.com/Mohammad-Alavi "Mohammad-Alavi (10 commits)")

---

Tags

laravelshopcarte-commerceshopping cart

### Embed Badge

![Health badge](/badges/mohammad-alavi-laravel-shoppingcart/health.svg)

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

###  Alternatives

[amsgames/laravel-shop

Package set to provide shop or e-commerce functionality (such as CART, ORDERS, TRANSACTIONS and ITEMS) to Laravel for customizable builds.

4845.9k](/packages/amsgames-laravel-shop)

PHPackages © 2026

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