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

AbandonedArchivedLibrary[Framework](/categories/framework)

mathewberry/cart
================

A simple, easy to use shopping cart for Laravel

0.2.2(9y ago)5136MITPHP

Since Feb 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mathewberry/cart)[ Packagist](https://packagist.org/packages/mathewberry/cart)[ RSS](/packages/mathewberry-cart/feed)WikiDiscussions master Synced 3w ago

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

Shopping cart component
=======================

[](#shopping-cart-component)

Shopping cart component includes a fully intergratable shopping cart with lots of rich features.

**Laravel 5.4 Support for version 0.2.0**

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

[](#installation)

To install through composer simply use the following command:

```
composer require mathewberry/cart
```

Next add

```
Cart` => \Mathewberry\Cart\Facades\Cart::class
```

to `config/app.php`

Features
--------

[](#features)

- Get the subtotal
- Get the total
- Get the delivery price
- Get the voucher price
- Get the quantity
- Get the cart total
- Add a product
- Add a voucher
- Check if the cart has a product
- Update the cart
- Remove an item from the cart
- Clear the cart

Usage
-----

[](#usage)

### Get product

[](#get-product)

```
$product = Cart::get($product_id);
```

#### Array Structure

[](#array-structure)

```
// Example
[
    "id" => 24,
    "price" => 99.99,
    "quantity" => 2,
    "options" => [...]
]
```

#### Displaying

[](#displaying)

```
{{ $product['options']['name'] }} {{ $product['options']['model'] }}

```

#### Usages

[](#usages)

### Get all products

[](#get-all-products)

```
$products = Cart::content();
```

#### Array Structure

[](#array-structure-1)

```
// Example
[
    [
        "id" => 24,
        "price" => 99.99,
        "quantity" => 2,
        "options" => [...]
    ],
    [
        "id" => 34,
        "price" => 79.99,
        "quantity" => 1,
        "options" => [...]
    ]
]
```

### Get the subtotal

[](#get-the-subtotal)

```
// Return the total with shipping or voucher
Cart::subtotal();
```

### Add a new product

[](#add-a-new-product)

```
/* DATABASE ROW
 *
 * Id: 24
 * Name: 'My Product'
 * Model: 'AAA900'
 * Price: 99.99
 *
 */

$product = \App\Models\Product::select(['id', 'model', 'price'])->find(24);
$product_id = $product->id;
$price = $product->price;
$quantity = 1;

// You may add any options you wish.
$options = [
     'name' => $product->name,
     'image' => asset('images/my-product-image.jpg'),
     'model' => $product->model
];

Cart::add($product_id, $price, $quantity, $options)
```

### Get the total

[](#get-the-total)

```
// Returns the total of the cart
Cart::total();
```

### Get the delivery cost

[](#get-the-delivery-cost)

```
// Returns the delivery cost
Cart::delivery();
```

### Set the voucher

[](#set-the-voucher)

```
// Example Data
$id = 24;
$code = "MB25OFF"; // 25% Off
$discount = 25.00; // 25%
$is_fixed = false; // Percentage
$display = '-' . number_format($discount, 2) . '%'; // How it should be displayed to the customer.

Cart::voucher($id, $code, $discount, $is_fixed, $display);
```

### Get the voucher

[](#get-the-voucher)

```
Cart::voucher();
```

#### Structure

[](#structure)

```
[
    "id" => $voucher_id, // Voucher id
    "code" => $voucher_code, // Voucher code
    "display" => $voucher_display, // Customer friendly, e.g: "25%"
    "is_fixed" => $voucher_fixed, // Percentage voucher or fixed price
    "discount" => $voucher_discount_value // Value of voucher
]
```

#### Displaying

[](#displaying-1)

```
Code: {{ Cart::voucher()['code'] }}
Deducted: {{ Cart::voucher()['display'] }}
```

### Has product

[](#has-product)

```
// Returns true or false whether or not the product exists in the cart.
Cart::has($product_id);
```

### Get the total of a product

[](#get-the-total-of-a-product)

```
// Calculates the product price times quantity.
Cart::sum($product_id);
```

### Get the quantity of the cart

[](#get-the-quantity-of-the-cart)

```
// Return a list of all the products in the cart.
Cart::products();
```

### Update cart item

[](#update-cart-item)

```
// Add one to the current quantity
Cart::update($product_id);
```

```
// Custom quantity to add to existing quantity
Cart::update($product_id, $quantity);
```

### Remove from cart

[](#remove-from-cart)

```
// Remove a specific product from the cart.
Cart::remove($product_id);
```

### Clear the cart

[](#clear-the-cart)

```
// Clear the cart of ALL of it's data.
Cart::clear();
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

6

Last Release

3427d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7cb6dcfb4aae7dac964d1ffc4838ee22e27470e2c616d3ac309f1338e3689785?d=identicon)[berry9mathew](/maintainers/berry9mathew)

---

Top Contributors

[![mathewberry51](https://avatars.githubusercontent.com/u/19976645?v=4)](https://github.com/mathewberry51 "mathewberry51 (9 commits)")[![mathewberry](https://avatars.githubusercontent.com/u/10889016?v=4)](https://github.com/mathewberry "mathewberry (3 commits)")

---

Tags

ecommerce-storelaravelshopping-cart

### Embed Badge

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

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

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k91.3M282](/packages/laravel-horizon)[illuminate/routing

The Illuminate Routing package.

1239.0M2.9k](/packages/illuminate-routing)[laravel/ai

The official AI SDK for Laravel.

1.0k2.1M163](/packages/laravel-ai)[illuminate/http

The Illuminate Http package.

11937.2M6.6k](/packages/illuminate-http)[laravel/surveyor

Static analysis tool for Laravel applications.

8690.3k12](/packages/laravel-surveyor)

PHPackages © 2026

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