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

ActiveLibrary[Framework](/categories/framework)

miyaye/laravel-shopping-cart
============================

Shopping cart for Laravel Application.

v1.0.2(6y ago)013MITPHPPHP &gt;=5.5

Since Jul 22Pushed 6y agoCompare

[ Source](https://github.com/lilili001/cart)[ Packagist](https://packagist.org/packages/miyaye/laravel-shopping-cart)[ RSS](/packages/miyaye-laravel-shopping-cart/feed)WikiDiscussions master Synced 2d ago

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

Laravel Shopping Cart
=====================

[](#laravel-shopping-cart)

Shopping cart for Laravel Application 222.

[![Build Status](https://camo.githubusercontent.com/4f31347d7007c436f512f328f111874f7738a23b8ebccedfad8475bea314897f/68747470733a2f2f7472617669732d63692e6f72672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/overtrue/laravel-shopping-cart)[![Latest Stable Version](https://camo.githubusercontent.com/a945170e92f8bf503cbddab7458be133d3ba73256b84dea510ba529ec20f3a30/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f762f737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-shopping-cart)[![Latest Unstable Version](https://camo.githubusercontent.com/e23bf2e609ff115be9430c440ae01f420a91fbce9266f1b7982142eabd5ff25b/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f762f756e737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-shopping-cart)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6aaf45e34b041f2ec36e5d70c9385466ec6ea3ba30ef9eba8b68ed12ce3b3d92/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/overtrue/laravel-shopping-cart/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/5cdd5f0ae1e88c07b0b651d18e5e1b4c678c0c2931fced75182d6eedaadf1470/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/overtrue/laravel-shopping-cart/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/bdb0665346b8327a10ae71c82b9b10ecfc55ede509fcb8af2ce2cd705654ef51/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f646f776e6c6f616473)](https://packagist.org/packages/overtrue/laravel-shopping-cart)[![License](https://camo.githubusercontent.com/1ef6b3531ca6c7abeafd7f243ea8ff968631ac1da8d181e03cb3d71eda138dd7/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d73686f7070696e672d636172742f6c6963656e7365)](https://packagist.org/packages/overtrue/wechat)

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

[](#installation)

```
$ composer require "overtrue/laravel-shopping-cart:~2.0"
```

or add the following line to your project's `composer.json`:

```
"require": {
    "overtrue/laravel-shopping-cart": "~2.0"
}
```

then

```
$ composer update
```

After completion of the above, add the follow line to the section `providers` of `config/app.php`:

```
Overtrue\LaravelShoppingCart\ServiceProvider::class,
```

And add the follow line to the section `aliases`:

```
'ShoppingCart'      => Overtrue\LaravelShoppingCart\Facade::class,
```

Usage
=====

[](#usage)

### Add item to cart

[](#add-item-to-cart)

Add a new item.

```
Item | null ShoppingCart::add(
                    string | int $id,
                    string $name,
                    int $quantity,
                    int | float $price
                    [, array $attributes = []]
                 );
```

**example:**

```
$row = ShoppingCart::add(37, 'Item name', 5, 100.00, ['color' => 'red', 'size' => 'M']);
// Item:
//    id       => 37
//    name     => 'Item name'
//    qty      => 5
//    price    => 100.00
//    color    => 'red'
//    size     => 'M'
//    total    => 500.00
//    __raw_id => '8a48aa7c8e5202841ddaf767bb4d10da'
$rawId = $row->rawId();// get __raw_id
$row->qty; // 5
...
```

### Update item

[](#update-item)

Update the specified item.

```
Item ShoppingCart::update(string $rawId, int $quantity);
Item ShoppingCart::update(string $rawId, array $arrtibutes);
```

**example:**

```
ShoppingCart::update('8a48aa7c8e5202841ddaf767bb4d10da', ['name' => 'New item name');
// or only update quantity
ShoppingCart::update('8a48aa7c8e5202841ddaf767bb4d10da', 5);
```

### Get all items

[](#get-all-items)

Get all the items.

```
Collection ShoppingCart::all();
```

**example:**

```
$items = ShoppingCart::all();
```

### Get item

[](#get-item)

Get the specified item.

```
Item ShoppingCart::get(string $rawId);
```

**example:**

```
$item = ShoppingCart::get('8a48aa7c8e5202841ddaf767bb4d10da');
```

### Remove item

[](#remove-item)

Remove the specified item by raw ID.

```
boolean ShoppingCart::remove(string $rawId);
```

**example:**

```
ShoppingCart::remove('8a48aa7c8e5202841ddaf767bb4d10da');
```

### Destroy cart

[](#destroy-cart)

Clean Shopping Cart.

```
boolean ShoppingCart::destroy();
boolean ShoppingCart::clean(); // alias of destroy();
```

**example:**

```
ShoppingCart::destroy();// or ShoppingCart::clean();
```

### Total price

[](#total-price)

Returns the total of all items.

```
int | float ShoppingCart::total(); // alias of totalPrice();
int | float ShoppingCart::totalPrice();
```

**example:**

```
$total = ShoppingCart::total();
// or
$total = ShoppingCart::totalPrice();
```

### Count rows

[](#count-rows)

Return the number of rows.

```
int ShoppingCart::countRows();
```

**example:**

```
ShoppingCart::add(37, 'Item name', 5, 100.00, ['color' => 'red', 'size' => 'M']);
ShoppingCart::add(37, 'Item name', 1, 100.00, ['color' => 'red', 'size' => 'M']);
ShoppingCart::add(37, 'Item name', 5, 100.00, ['color' => 'red', 'size' => 'M']);
ShoppingCart::add(127, 'foobar', 15, 100.00, ['color' => 'green', 'size' => 'S']);
$rows = ShoppingCart::countRows(); // 2
```

### Count quantity

[](#count-quantity)

Returns the quantity of all items

```
int ShoppingCart::count($totalItems = true);
```

`$totalItems` : When `false`,will return the number of rows.

**example:**

```
ShoppingCart::add(37, 'Item name', 5, 100.00, ['color' => 'red', 'size' => 'M']);
ShoppingCart::add(37, 'Item name', 1, 100.00, ['color' => 'red', 'size' => 'M']);
ShoppingCart::add(37, 'Item name', 5, 100.00, ['color' => 'red', 'size' => 'M']);
$count = ShoppingCart::count(); // 11 (5+1+5)
```

### Search items

[](#search-items)

Search items by property.

```
Collection ShoppingCart::search(array $conditions);
```

**example:**

```
$items = ShoppingCart::search(['color' => 'red']);
$items = ShoppingCart::search(['name' => 'Item name']);
$items = ShoppingCart::search(['qty' => 10]);
```

### Check empty

[](#check-empty)

```
bool ShoppingCart::isEmpty();
```

### Specifies the associated model

[](#specifies-the-associated-model)

Specifies the associated model of item.

```
Cart ShoppingCart::associate(string $modelName);
```

**example:**

```
ShoppingCart::associate('App\Models\Product');
$item = ShoppingCart::get('8a48aa7c8e5202841ddaf767bb4d10da');
$item->product->name; // $item->product is instanceof 'App\Models\Product'
```

The Collection And Item
=======================

[](#the-collection-and-item)

`Collection` and `Overtrue\LaravelShoppingCart\Item` are instanceof `Illuminate\Support\Collection`, Usage Refer to：[Collections - Laravel doc.](http://laravel.com/docs/5.0/collections)

properties of `Overtrue\LaravelShoppingCart\Item`:

- `id` - your goods item ID.
- `name` - Name of item.
- `qty` - Quantity of item.
- `price` - Unit price of item.
- `total` - Total price of item.
- `__raw_id` - Unique ID of row.
- `__model` - Name of item associated Model.
- ... custom attributes.

And methods:

- `rawId()` - Return the raw ID of item.

Events
======

[](#events)

Event NameParameters`shopping_cart.adding`($attributes, $cart);`shopping_cart.added`($attributes, $cart);`shopping_cart.updating`($row, $cart);`shopping_cart.updated`($row, $cart);`shopping_cart.removing`($row, $cart);`shopping_cart.removed`($row, $cart);`shopping_cart.destroying`($cart);`shopping_cart.destroyed`($cart);You can easily handle these events, for example:

```
Event::on('shopping_cart.adding', function($attributes, $cart){
    // code
});
```

License
=======

[](#license)

MIT

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

2488d ago

### Community

Maintainers

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

---

Tags

laravelshoppingshopping cart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[lukepolo/laracart

A simple cart for Laravel

583135.4k1](/packages/lukepolo-laracart)[jsdecena/laracom

Laravel powered e-commerce

2.0k4.4k](/packages/jsdecena-laracom)[treestoneit/shopping-cart

An easy-to-use shopping cart for Laravel

6263.0k2](/packages/treestoneit-shopping-cart)

PHPackages © 2026

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