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

ActiveLibrary

yabhq/laravel-cart
==================

Simple yet customizable Laravel shopping cart

v0.20.1(3y ago)213.0k↓50%10MITPHPPHP ^8.0CI failing

Since Dec 15Pushed 3y ago2 watchersCompare

[ Source](https://github.com/yabhq/laravel-cart)[ Packagist](https://packagist.org/packages/yabhq/laravel-cart)[ Docs](https://github.com/yabhq/laravel-cart)[ RSS](/packages/yabhq-laravel-cart/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (27)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/71c2d4fa005bebd9ae20e543c9a1d8432bde87c52f76c99efdf663177b83fd91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79616268712f6c61726176656c2d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yabhq/laravel-cart)[![CircleCI](https://camo.githubusercontent.com/96314f72f5b1c419bcb2f840342b29d81ffbd0c86bd577d6dda41b5ff2186706/68747470733a2f2f636972636c6563692e636f6d2f67682f79616268712f6c61726176656c2d636172742e7376673f7374796c653d737667)](https://circleci.com/gh/yabhq/laravel-cart)

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

[](#laravel-shopping-cart)

A simple yet customizable Laravel shopping cart implementation.

Provides RESTful API endpoints out of the box to help with front-end / SPA integrations.

Table of Contents
-----------------

[](#table-of-contents)

[Requirements](#requirements)
[Installation](#installation)
[Usage](#usage)[The Checkout Class](#the-checkout-class)
[Customization](#customization)
[License](#license)

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

[](#requirements)

- PHP 8+
- Laravel 8.x

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

[](#installation)

```
composer require yabhq/laravel-cart
```

The package publishes some migrations, routes (for optional use) and classes for further customizing your store logistics.

```
php artisan vendor:publish --provider="Yab\ShoppingCart\ShoppingCartServiceProvider"
```

Full list of published files:

- database/migrations/2020\_12\_13\_000001\_create\_carts\_table
- database/migrations/2020\_12\_13\_000002\_create\_cart\_items\_table
- routes/checkout.php
- config/checkout.php
- app/Logistics/CartLogistics.php
- app/Logistics/ShippingLogistics.php
- app/Logistics/TaxLogistics.php
- app/Logistics/DiscountLogistics.php

Usage
-----

[](#usage)

First, simply implement the *Purchaseable* interface on your product (or other purchaseable) model.

**app/Models/Product.php**

```
use Yab\ShoppingCart\Traits\Purchaseable;
use Yab\ShoppingCart\Contracts\Purchaseable as PurchaseableInterface;

class Product extends Model implements PurchaseableInterface
{
    use Purchaseable;
}
```

Next we should implement the *Purchaser* interface on the model representing the end customer.

**app/Models/Customer.php**

```
use Yab\ShoppingCart\Traits\Purchaser;
use Yab\ShoppingCart\Contracts\Purchaser as PurchaserInterface;

class Customer extends Model implements PurchaserInterface
{
    use Purchaser;
}
```

If you would like to use the built-in cart API endpoints, you can simply include the published *checkout.php* in your existing routes file.

**routes/api.php** (optional)

```
Route::group(['middleware' => ['example']], function () {
    require base_path('routes/checkout.php');
});
```

The Checkout Class
------------------

[](#the-checkout-class)

The package comes with a *Checkout* class which allows you to interact with the shopping cart.

```
use Yab\ShoppingCart\Checkout;
```

Creating or retrieving a checkout instance:

```
$checkout = Checkout::create();
// or
$checkout = Checkout::findById('uuid-123');
```

Getting the ID of an existing checkout:

```
$checkout->id();
```

Adding a custom field for a checkout:

```
$checkout->setCustomField('some key', 'some value');
```

Deleting a checkout:

```
$checkout->destroy();
```

Interacting with the underlying cart model and query builder:

```
// Yab\ShoppingCart\Models\Cart
$checkout->getCart();

// Illuminate\Database\Eloquent\Builder
$checkout->getCartBuilder();
```

Adding, updating or removing cart items:

```
// Add 1 qty of product and return the CartItem model
$item = $checkout->addItem($product, 1);

// Override the default unit price for the product
$item = $checkout->addItem($product, 1, 11.95);

// Add custom options to a checkout item
$item = $checkout->addItem(
    purchaseable: $product,
    qty: 1,
    options: [ 'size' => 'medium' ],
);

// Update the quantity of the item to 2
$checkout->updateItem($item->id, 2);

// Remove the item entirely
$checkout->removeItem($item->id);
```

Optionally set a purchaser entity (class must implement Purchaser interface):

```
$checkout->setPurchaser($customer);
```

Getting the shipping, subtotal, taxes and total:

```
$checkout->getShipping(); // 5.00
$checkout->getSubtotal(); // 110.00
$checkout->getDiscount(); // 10.00
$checkout->getTaxes(); // 13.00
$checkout->getTotal(); // 113.00
```

Customization
-------------

[](#customization)

Not every e-commerce store is the same. This package provides several "logistics" classes which allow you to hook into the core package logic and perform some common customizations. For example, you may specify how the tax, shipping and discount amounts are determined:

**app/Logistics/TaxLogistics.php**

```
public static function getTaxes(Checkout $checkout) : float
```

**app/Logistics/ShippingLogistics.php**

```
public static function getShippingCost(Checkout $checkout) : float
```

**app/Logistics/DiscountLogistics.php**

```
public static function getDiscountFromCode(Checkout $checkout, string $code) : float
```

**app/Logistics/CartLogistics.php**

```
public static function getPurchaseable(string $type, mixed $id) : mixed
public static function beforeCartItemAdded(Checkout $checkout, mixed $purchaseable, int $qty) : void
public static function hasInfoNeededToCalculateTotal(Checkout $checkout) : bool
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.9% 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 ~27 days

Recently: every ~124 days

Total

24

Last Release

1345d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6893042?v=4)[Jim Hlad](/maintainers/jimhlad)[@jimhlad](https://github.com/jimhlad)

---

Top Contributors

[![jimhlad](https://avatars.githubusercontent.com/u/6893042?v=4)](https://github.com/jimhlad "jimhlad (93 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![chrisblackwell](https://avatars.githubusercontent.com/u/856537?v=4)](https://github.com/chrisblackwell "chrisblackwell (1 commits)")

---

Tags

laravelcartshoppingshopping cart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[lukepolo/laracart

A simple cart for Laravel

583135.4k1](/packages/lukepolo-laracart)[amsgames/laravel-shop

Package set to provide shop or e-commerce functionality (such as CART, ORDERS, TRANSACTIONS and ITEMS) to Laravel for customizable builds.

4845.9k](/packages/amsgames-laravel-shop)[realrashid/cart

Meet Cart — your ultimate solution for seamless shopping cart functionality in Laravel applications. Cart simplifies the complexities of shopping cart operations, from product additions to total calculations, ensuring a frictionless user experience.

1093.6k](/packages/realrashid-cart)[wearepixel/laravel-cart

A cart implementation for Laravel

1310.5k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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