PHPackages                             mikehins/laravel-shoppingcart - 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. mikehins/laravel-shoppingcart

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

mikehins/laravel-shoppingcart
=============================

Laravel Shopping Cart

042PHPCI passing

Since Mar 17Pushed 3mo agoCompare

[ Source](https://github.com/mikehins/laravel-shoppingcart)[ Packagist](https://packagist.org/packages/mikehins/laravel-shoppingcart)[ RSS](/packages/mikehins-laravel-shoppingcart/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (13)Versions (2)Used By (0)

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

[](#laravel-shopping-cart)

[![Latest Stable Version](https://camo.githubusercontent.com/b683ba4010fa2e2bbe757125b401f11da038d980ffbfea028e2da96b36db7020/68747470733a2f2f706f7365722e707567782e6f72672f6d696b6568696e732f6c61726176656c2d73686f7070696e67636172742f76)](https://packagist.org/packages/mikehins/laravel-shoppingcart)[![License](https://camo.githubusercontent.com/41b431993f54394e0c5035535f249f5480b61473b34273a68e189fa3e0734fad/68747470733a2f2f706f7365722e707567782e6f72672f6d696b6568696e732f6c61726176656c2d73686f7070696e67636172742f6c6963656e73652e737667)](https://packagist.org/packages/mikehins/laravel-shoppingcart)

A modern, strictly typed, and performance-oriented Shopping Cart implementation for Laravel.

📊 Quality Metrics
-----------------

[](#-quality-metrics)

MetricStatus**Tests**71 passing**Type Coverage**97.1%**Mutation Score**60.5%**PHPStan Level**5**Code Style**Laravel Pint🌟 Modernization &amp; Attribution
---------------------------------

[](#-modernization--attribution)

This package is a modernized fork of the original [darryldecode/laravelshoppingcart](https://github.com/darryldecode/laravelshoppingcart). The original package provided a robust foundation but has effectively reached end-of-life for modern applications.

**Why this fork exists:**

- **Laravel 12+ / PHP 8.3+ Support:** Rebuilt to support the latest ecosystems without legacy baggage.
- **Strict Typing:** All classes use `declare(strict_types=1)` with typed properties and return types.
- **PHPStan Validated:** Static analysis ensures contract compliance and reduces runtime errors.
- **Pest Test Suite:** The entire test suite has been migrated from PHPUnit to Pest v3 for better readability.
- **Mutation Testing:** Core logic validated with Pest's mutation testing plugin.

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require mikehins/laravel-shoppingcart
```

The service provider and facade are automatically discovered.

### Configuration (Optional)

[](#configuration-optional)

Publish the configuration file:

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

🛠 Basic Usage
-------------

[](#-basic-usage)

### Adding items

[](#adding-items)

```
// Simple addition
cart()->add([
    'id' => 456, // Unique ID per item
    'name' => 'Sample Item',
    'price' => 50.00,
    'quantity' => 1,
    'attributes' => [
        'size' => 'L',
        'color' => 'Red'
    ]
]);

// With conditions
cart()->add([
    'id' => 456,
    'name' => 'Sample Item',
    'price' => 50.00,
    'quantity' => 1,
    'attributes' => [],
    'conditions' => $condition // CartCondition instance or array of them
]);
```

### Retrieving Cart Content

[](#retrieving-cart-content)

```
$cartCollection = cart()->getContent();
```

### Updating Items

[](#updating-items)

```
cart()->update(456, [
    'name' => 'New Item Name', // New name
    'price' => 98.67, // New price
]);

// Relative quantity update (add 2 to existing)
cart()->update(456, [
    'quantity' => 2,
]);

// Absolute quantity update (set quantity to 4)
cart()->update(456, [
    'quantity' => [
        'relative' => false,
        'value' => 4
    ],
]);
```

### Removing Items

[](#removing-items)

```
cart()->remove(456);
```

### Clearing Cart

[](#clearing-cart)

```
cart()->clear();
```

🏷 Conditions (Coupons, Taxes, Shipping)
---------------------------------------

[](#-conditions-coupons-taxes-shipping)

Conditions can be applied to the **whole cart** or **specific items**.

### Cart-Wide Conditions

[](#cart-wide-conditions)

Target either `subtotal` or `total`.

```
use Mikehins\Cart\CartCondition;

$condition = new CartCondition([
     'name' => 'VAT 12.5%',
     'type' => 'tax',
     'target' => 'subtotal', // Applied when getSubTotal() is called
     'value' => '12.5%', // Can be percentage string or absolute '-10'
     'attributes' => [
     	'description' => 'Value added tax',
     ]
]);

cart()->condition($condition);
```

### Item-Specific Conditions

[](#item-specific-conditions)

Conditions applied to a specific item.

```
$condition = new CartCondition([
    'name' => 'SALE 5%',
    'type' => 'sale',
    'value' => '-5%',
]);

cart()->add([
    'id' => 456,
    'name' => 'Sample Item',
    'price' => 100,
    'quantity' => 1,
    'conditions' => $condition
]);
```

🎯 Events
--------

[](#-events)

The cart fires events for all major operations, allowing you to hook into the cart lifecycle:

EventDescription`cart.created`Fired when a new cart instance is created`cart.adding`Fired before an item is added (return `false` to cancel)`cart.added`Fired after an item is added`cart.updating`Fired before an item is updated (return `false` to cancel)`cart.updated`Fired after an item is updated`cart.removing`Fired before an item is removed (return `false` to cancel)`cart.removed`Fired after an item is removed`cart.clearing`Fired before cart is cleared (return `false` to cancel)`cart.cleared`Fired after cart is cleared🧪 Testing
---------

[](#-testing)

We use Pest for testing. The test suite includes:

- **Unit Tests**: Core cart functionality
- **Mutation Testing**: Validates test quality by ensuring tests catch code changes
- **Type Coverage**: Ensures proper type declarations across the codebase
- **Static Analysis**: PHPStan validation

To run the full test suite:

```
composer test
```

This runs:

1. `pest --parallel` - Unit tests
2. `pest --mutate --parallel` - Mutation testing
3. `pest --type-coverage --min=97 --parallel` - Type coverage check
4. `pint --preset laravel` - Code style fixing
5. `rector process --dry-run` - Automated refactoring check
6. `phpstan analyse` - Static analysis

📄 License
---------

[](#-license)

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

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance53

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

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

Unknown

Total

1

Last Release

168d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1184036?v=4)[Mike Hins](/maintainers/mikehins)[@mikehins](https://github.com/mikehins)

---

Top Contributors

[![mikehins](https://avatars.githubusercontent.com/u/1184036?v=4)](https://github.com/mikehins "mikehins (4 commits)")[![mikehins-fliip](https://avatars.githubusercontent.com/u/258842908?v=4)](https://github.com/mikehins-fliip "mikehins-fliip (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mikehins-laravel-shoppingcart/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[illuminate/view

The Illuminate View package.

13047.0M2.2k](/packages/illuminate-view)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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