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

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

mohammadv184/laravel-cart
=========================

A Cart for Laravel Framework

v2.3.2(4y ago)231MITPHPPHP &gt;=7.3

Since Jul 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mohammadv184/laravel-cart)[ Packagist](https://packagist.org/packages/mohammadv184/laravel-cart)[ RSS](/packages/mohammadv184-laravel-cart/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (19)Used By (0)

laravel-cart
============

[](#laravel-cart)

[![Latest Stable Version](https://camo.githubusercontent.com/3d86e0a82698b0287bd76c6c283134d170f62793ceb8dfc5abfd99d302e2e111/687474703a2f2f706f7365722e707567782e6f72672f6d6f68616d6d6164763138342f6c61726176656c2d636172742f76)](https://packagist.org/packages/mohammadv184/laravel-cart)[![Total Downloads](https://camo.githubusercontent.com/4d01a3f7f82d4fafbb020613beb8758ac9e458c1bb1c75e37462d89a21f38783/687474703a2f2f706f7365722e707567782e6f72672f6d6f68616d6d6164763138342f6c61726176656c2d636172742f646f776e6c6f616473)](https://packagist.org/packages/mohammadv184/laravel-cart)[![Monthly Downloads](https://camo.githubusercontent.com/89f824e9e7cecd2e3c2263ec8995a58ca7394ed00b178e13110410c923676143/687474703a2f2f706f7365722e707567782e6f72672f6d6f68616d6d6164763138342f6c61726176656c2d636172742f642f6d6f6e74686c79)](https://packagist.org/packages/mohammadv184/laravel-cart)[![Build Status](https://camo.githubusercontent.com/90d0bbccd508ffd45aa44c763929b860fee46789c82a93f90b5615f803530e7d/68747470733a2f2f7472617669732d63692e636f6d2f6d6f68616d6d6164763138342f6c61726176656c2d636172742e7376673f6272616e63683d6d61696e)](https://travis-ci.com/mohammadv184/laravel-cart)[![License](https://camo.githubusercontent.com/972815b7efb61d4f19b33c9109f13232629b6491f932c8bbcaf68386b090b645/687474703a2f2f706f7365722e707567782e6f72672f6d6f68616d6d6164763138342f6c61726176656c2d636172742f6c6963656e7365)](https://packagist.org/packages/mohammadv184/laravel-cart)

A Shoping Cart for Laravel Framework

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

[](#installation)

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

Run the Composer require command from the Terminal:

```
composer require mohammadv184/laravel-cart

```

If you're using Laravel 5.5, this is all there is to do.

Should you still be on version 5.4 of Laravel, the final steps for you are to add the service provider of the package and alias the package. To do this open your `config/app.php` file.

Add a new line to the `providers` array:

```
Mohammadv184\Cart\CartProvider::class

```

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

```
'Cart' => Mohammadv184\Cart\Facades\Cart::class,

```

Now you're ready to start using the laravel-cart in your application.

### Database

[](#database)

To save cart into the database, the package needs to know which what the name of the table is. By default the package will use a table named `cart_items`. If you want to change these options, you'll have to publish the `config` file.

```
php artisan vendor:publish --provider="Mohammadv184\Cart\CartServiceProvider" --tag="config"

```

This will give you a `cart.php` config file in which you can make the changes.

To make your life easy, the package also includes a ready to use `migration` which you can publish by running:

```
php artisan vendor:publish --provider="Mohammadv184\Cart\CartServiceProvider" --tag="migrations"

```

This will place a `cart_items` table's migration file into `database/migrations` directory. Now all you have to do is run `php artisan migrate` to migrate your database.

Overview
--------

[](#overview)

Look at one of the following topics to learn more about Laravel-cart

- [Usage](#usage)
- [Example](#example)

Usage
-----

[](#usage)

The laravel-cart gives you the following methods to use:

### Cart::put()

[](#cartput)

Adding an item to the cart is really simple, you just use the `put()` method, which accepts a variety of parameters.

In its most basic form you can specify the quantity, price and product model of the product you'd like to add to the cart.

```
$product=Product::find(1);
Cart::put([
    "price"=>10,
    "quantity"=>1
],$product);
```

### Cart::update()

[](#cartupdate)

To update an item in the cart, you'll first need the rowId of the item. Next you can use the `update()` method to update it.

If you simply want to update the quantity, you'll pass the update method the product model or id and the new quantity:

```
$product=Product::find(1);
Cart::update(2,$product); // Will update the quantity
```

OR

```
$id = 'Biuwla5871';
Cart::update($id, 2); // Will update the quantity
```

If you want to update more attributes of the item, you can either pass the update method an array as the first parameter. This way you can update all information of the item with the given id.

```
Cart::update(['price' => 1000],"16cdac2cs8"); // Will update the price
$product=Product::find(1);
Cart::update(['id'=>"1c6a4c6a75",'price'=>1000], $product); // Will update the id and price
```

### Cart::delete()

[](#cartdelete)

To delete an item for the cart, you'll again need the product model or id. This id you simply pass to the `delete()` method and it will delete the item from the cart.

```
$product=Product::find(1);
Cart::delete($product);
```

OR

```
$id = 'da39a3ee5e';
Cart::delete($id);
```

### Cart::get()

[](#cartget)

If you want to get an item from the cart using its id or product model, you can simply call the `get()` method on the cart and pass it the id or product model.

```
$product = Product::find(1);
Cart::get($product);
```

OR

```
$id = 'da39a3ee5e';
Cart::get($id);
```

### Cart::all()

[](#cartall)

Of course you also want to get the all items in cart. This is where you'll use the `all` method. This method will return a Collection of Cart Items.

```
Cart::all();
```

### Cart::flush()

[](#cartflush)

If you want to completely delete the all items of a cart, you can call the flush method on the cart. This will delete all Cart Items from the cart for the current cart instance.

```
Cart::flush();
```

### Cart::totalPrice()

[](#carttotalprice)

The `totalPrice()` method can be used to get the totalPrice of all items in the cart.

```
Cart::totalPrice();
```

Example
-------

[](#example)

Below is a little example of how to list the cart content in a table:

```
// Add some items in your Controller.
$product=Product::find(1);
Cart::put(['quantity'=>1,'price'=>9.99],$product);
$product=Product::find(2);
Cart::put(['quantity'=>2,'price'=>10],$product);
// Display the content in a View.

           	Product
           	quantity
           	Price

   		@foreach(Cart::all() as $row)

               		{{$row->product->name}}

           		{{$row->quantity}}
           		${{$row->price}}

	   	@endforeach

   			&nbsp;
   			Total
   			{{Cart::totalPrice()}}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

18

Last Release

1765d ago

Major Versions

v1.4.1 → v2.0.02021-07-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77800167?v=4)[Mohammad Abbasi](/maintainers/mohammadv184)[@mohammadv184](https://github.com/mohammadv184)

---

Top Contributors

[![mohammadv184](https://avatars.githubusercontent.com/u/77800167?v=4)](https://github.com/mohammadv184 "mohammadv184 (119 commits)")

---

Tags

cartlaravelshoplaravelcartshopping cart

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[wearepixel/laravel-cart

A cart implementation for Laravel

1310.5k](/packages/wearepixel-laravel-cart)[ultrono/laravelshoppingcart-1

Laravel 11 and above Shopping cart

1110.0k](/packages/ultrono-laravelshoppingcart-1)

PHPackages © 2026

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