PHPackages                             tomshaw/shopcart - 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. tomshaw/shopcart

ActiveLibrary[Framework](/categories/framework)

tomshaw/shopcart
================

A modern easy to use Laravel shopping cart

v2.3.0(1mo ago)433[1 PRs](https://github.com/tomshaw/shopcart/pulls)MITPHPPHP ^8.5CI passing

Since Jul 7Pushed 1w ago1 watchersCompare

[ Source](https://github.com/tomshaw/shopcart)[ Packagist](https://packagist.org/packages/tomshaw/shopcart)[ RSS](/packages/tomshaw-shopcart/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (30)Versions (21)Used By (0)

ShopCart 🛒
==========

[](#shopcart-)

[![GitHub Workflow Status](https://camo.githubusercontent.com/b142d05f98481de8611fe5f1f76b4e7595aa2016e4bff33966b11a19c0bd9af1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d736861772f73686f70636172742f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://camo.githubusercontent.com/b142d05f98481de8611fe5f1f76b4e7595aa2016e4bff33966b11a19c0bd9af1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d736861772f73686f70636172742f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265266c6162656c3d7465737473)[![issues](https://camo.githubusercontent.com/2546c508ab37641139084cc9ae99e4cd8f8dcbe69cd155b4e6d5ed2aa590efb7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/2546c508ab37641139084cc9ae99e4cd8f8dcbe69cd155b4e6d5ed2aa590efb7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)[![forks](https://camo.githubusercontent.com/8e00769bef862797f9462946423c7379710cfe3760f18fad3c7f1bd1c66fcd9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/8e00769bef862797f9462946423c7379710cfe3760f18fad3c7f1bd1c66fcd9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)[![stars](https://camo.githubusercontent.com/849e8c06c8b19947ea19be44066fb6bf25ac9ac107ad5094b2b31985255a0085/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)](https://camo.githubusercontent.com/849e8c06c8b19947ea19be44066fb6bf25ac9ac107ad5094b2b31985255a0085/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f746f6d736861772f73686f70636172743f7374796c653d666c6174266c6f676f3d6170707665796f72)[![GitHub license](https://camo.githubusercontent.com/de0cdab54a4863ba65a83d58649138b4529de01d49c833f7b2bb2a13d49858c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f6d736861772f73686f7063617274)](https://github.com/tomshaw/shopcart/blob/master/LICENSE)

ShopCart is a modern easy to use [Laravel](https://laravel.com) shopping cart...

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

[](#installation)

You can install the package via composer:

```
composer require tomshaw/shopcart
```

Publish configuration file

```
php artisan vendor:publish --provider="TomShaw\ShopCart\Providers\ShopCartServiceProvider" --tag=config

```

Requirements
------------

[](#requirements)

- PHP 8.5+
- Laravel 13.0

Basic Usage
-----------

[](#basic-usage)

Adding an item to the shopping cart.

> Note: Cart item constructor properties are validated when creating or updating cart items.

> Note: A unique random integer `rowId` is created and used to identify cart items.

```
use TomShaw\ShopCart\{Cart, CartItem};

$cartItem = CartItem::make(id: $product->id, name: $product->name, quantity: 1, price: $product->price);

Cart::add($cartItem);
```

Adding an item with product options to the shopping cart.

```
$cartItem = CartItem::make($product->id, $product->name, 1, $product->price);

$cartItem->options['size'] = 'XL';
$cartItem->options['logo'] = 'Laravel Rocks';

Cart::add($cartItem);
```

Accessing product options.

```
// Array access
$size = $cartItem->options['size'];

// Or using Collection methods
$size = $cartItem->options->get('size');
$cartItem->options->put('color', 'blue');
$hasSize = $cartItem->options->has('size');
```

Updating an item and product options in the shopping cart.

```
$cartItem = Cart::all()->where('id', '===', $id)->first();

$cartItem->quantity = 5;
$cartItem->options['size'] = '2XL';

Cart::update($cartItem);
```

Removing an item from the shopping cart.

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

Deleting the shopping cart after checkout.

```
Cart::forget();
```

Cart Totals
-----------

[](#cart-totals)

> Sums the properties: `tax`, `price`, `subtotal` and `quantity`.

```
$totalPrice = Cart::total('price');
```

```
$totalQuantity = Cart::total(property: 'quantity', numberFormat: false);
```

```
$subTotal = Cart::total('subtotal');
```

```
$totalTax = Cart::total('tax');
```

Computed Properties
-------------------

[](#computed-properties)

Cart items automatically calculate `subTotal`, `totalTax`, and `totalPrice`. These values are computed on-demand and are always accurate.

```
$cartItem = CartItem::make(id: 1, name: 'Product', quantity: 2, price: 100.00, tax: 8.5);

// Automatically computed properties
echo $cartItem->subTotal;    // 200.00 (quantity * price)
echo $cartItem->totalTax;    // 17.00 (subTotal * tax / 100)
echo $cartItem->totalPrice;  // 217.00 (subTotal + totalTax)

// Values update automatically when properties change
$cartItem->quantity = 3;
echo $cartItem->subTotal;    // 300.00 (automatically recalculated)
```

Tax Rates
---------

[](#tax-rates)

To set a default tax rate add the following environment variable in your application `.env`.

```
SHOPCART_DEFAULT_TAXRATE=9.547
```

You can easily apply item specific tax rates at run time.

```
use TomShaw\ShopCart\{Cart, CartItem};

Cart::add(CartItem::make(tax: 6.250, ...));
```

Number Formatting
-----------------

[](#number-formatting)

Number formating is handled by adding the following environment variables to your application `.env`.

```
SHOPCART_DECIMALS=2
SHOPCART_DECIMAL_SEPARATOR="."
SHOPCART_THOUSANDS_SEPARATOR=","
```

Cart Methods
------------

[](#cart-methods)

Get item from collection by `rowId`.

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

Check if cart item exists by `rowId`.

```
$boolean = Cart::has($rowId);
```

Get cart as collection or array.

```
$cartItems = Cart::all(bool $toArray = false);
```

Use Laravel Collection methods for advanced operations.

```
// Search for specific cart items
$cartItems = Cart::all()->where('id', '===', $productId);

// Check if cart is empty
$isEmpty = Cart::all()->isEmpty();
$isNotEmpty = Cart::all()->isNotEmpty();

// Filter, map, or use any Collection method
$total = Cart::all()->sum('totalPrice');
$firstItem = Cart::all()->first();
```

Casting the cart as an `array` or `json`;

```
Cart::toArray();
```

```
Cart::toJson();
```

Changelog
---------

[](#changelog)

For changes made to the project, see the [Changelog](CHANGELOG.md).

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE) for more information.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 94.8% 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 ~64 days

Recently: every ~29 days

Total

17

Last Release

57d ago

Major Versions

v1.5.2 → v2.0.02026-01-11

PHP version history (5 changes)v1.0.0PHP ^8.1

v1.4.3PHP ^8.1|^8.2

v1.5.1PHP ^8.1|^8.2|^8.3|^8.4

v2.0.0PHP ^8.4|^8.5

v2.0.1PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/14fd02efdbaf6247b61c9846697c86dabcbf430374aeff0d80e509d95d186658?d=identicon)[Tom Shaw](/maintainers/Tom%20Shaw)

---

Top Contributors

[![tomshaw](https://avatars.githubusercontent.com/u/32818?v=4)](https://github.com/tomshaw "tomshaw (92 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

laravelecommerceshopping cartshopcart

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomshaw-shopcart/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[barryvdh/laravel-debugbar

PHP Debugbar integration for Laravel

19.3k133.0M757](/packages/barryvdh-laravel-debugbar)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M305](/packages/laravel-horizon)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.3k2.3M65](/packages/fruitcake-laravel-debugbar)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)

PHPackages © 2026

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