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

ActiveLibrary[Framework](/categories/framework)

jimmitjoo/cart
==============

A simple Laravel Cart.

15PHP

Since Nov 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jimmitjoo/cart)[ Packagist](https://packagist.org/packages/jimmitjoo/cart)[ RSS](/packages/jimmitjoo-cart/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

A Shopping Cart for Laravel 8
=============================

[](#a-shopping-cart-for-laravel-8)

[![Build Status](https://camo.githubusercontent.com/b73ec151341e7fcfad44fab3334e2f6d74061f28adfe6b7fb55d18ab723b779f/68747470733a2f2f6170702e7472617669732d63692e636f6d2f6a696d6d69746a6f6f2f636172742e7376673f6272616e63683d6d61696e)](https://app.travis-ci.com/jimmitjoo/cart)

We require PHP 8.

#### Install the package.

[](#install-the-package)

`composer require jimmitjoo/cart`

#### Publish the config and migrations.

[](#publish-the-config-and-migrations)

`php artisan vendor:publish --tag=laravel-cart`

#### You may configure your own models for Cart and CartItem.

[](#you-may-configure-your-own-models-for-cart-and-cartitem)

To make this work you need to implement contracts for both models.

By default we expect both the Cart and CartItem model to use Uuids as identifiers.

```
class Cart extends Model implements CartContract
{
    use UsesUuids;
}
```

```
class CartItem extends Model implements CartItemContract
{
    use UsesUuids;
}
```

Create a new Cart
-----------------

[](#create-a-new-cart)

For example, you can create a new Cart for a user that for some reason doesn't already got a cart.

To use a new cart you should store the ID, which is a uuid string, of the cart somewhere. `$cart->id`

```
$cart = (new CreateCartAction)->execute();
```

### Create a new Cart with attributes

[](#create-a-new-cart-with-attributes)

For example you can create a Cart belonging to a specific User of your system.

```
$cartData = new CartData((int) $userId);

$cart = (new CreateCartAction)->execute($cartData);
```

You can add a note to a cart as well. For example a note can tell you from where the Cart was created or something other important. Typehints just to clarify what type is expected by the CartData object.

```
$cartData = new CartData((int) $userId, (string) $note);

$cart = (new CreateCartAction)->execute($cartData);
```

Add a product to your Cart
--------------------------

[](#add-a-product-to-your-cart)

So there are a number of ways to do this.

`Purchasable` is a trait you can add to any model you want your users to be able to purchase.

```
$cart->addToCart(Purchasable $purchasable, int $amount = 1, int $discount = 0);
```

You can chain multiple product additions.

```
$cart
->addToCart(Purchasable $purchasable)
->addToCart(Purchasable $purchasable);
```

Or you can specifically create a CartItem by yourself by attaching the cart ID.

```
$cartItemData = new CartItemData(
    1, // Amount of products.
    300, // Current price (minus discount) of the product.
    100, // The discount,
    'Personalized product', // Custom product name
    null, // You could add a purchasable id here
    null, // And the purchasable type here
    $this->cart->id, // Add this item to a cart
);

$cartItem = (new AddCartItemToCartAction)->execute($cartItemData);
```

Update a cart item
------------------

[](#update-a-cart-item)

```
$cartItem = CartItem::find($existingItemId);

$cartItemData = new CartItemData(
    1, // Amount of products.
    88, // Current price (minus discount) of the product.
    12, // The discount,
    'Updated product name', // Custom product name
    null, // You could add a purchasable id here
    null, // And the purchasable type here
    null, // We don't need to specify the cart on update...
    $cartItem->id, // ID of the item to update
);

$cartItem = (new UpdateCartItemAction)->execute($cartItemData);
```

Remove a cart item
------------------

[](#remove-a-cart-item)

```
$cartItemToRemove = CartItem::find($existingItemId);

(new RemoveCartItemAction)->execute($cartItemToRemove);
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/19e8958ea0fdc2afe38ee2364c359da48c1ddca12b80161fb50f316839bc96b2?d=identicon)[jimmitjoo](/maintainers/jimmitjoo)

---

Top Contributors

[![jimmitjoo](https://avatars.githubusercontent.com/u/5941943?v=4)](https://github.com/jimmitjoo "jimmitjoo (28 commits)")

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M119](/packages/cakephp-chronos)

PHPackages © 2026

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