PHPackages                             nhanchaukp/laracart - 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. [Database &amp; ORM](/categories/database)
4. /
5. nhanchaukp/laracart

ActiveLibrary[Database &amp; ORM](/categories/database)

nhanchaukp/laracart
===================

Enhanced Laravel shopping cart package with multiple storage drivers

1.0.2(8mo ago)0446MITPHPPHP ^8.1

Since Apr 17Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/nhanchaukp/laracart)[ Packagist](https://packagist.org/packages/nhanchaukp/laracart)[ RSS](/packages/nhanchaukp-laracart/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (2)Versions (7)Used By (0)

[![LaraCart](https://camo.githubusercontent.com/5e5c2396ff1936278762f026ef0075fff20ce3ef11d3a1b667573abc23b05ba0/68747470733a2f2f736f6369616c6966792e6769742e63692f6e68616e636861756b702f6c617261636172742f696d6167653f637573746f6d5f6465736372697074696f6e3d4c617261436172742b69732b612b4c61726176656c2b7061636b6167652b746861742b70726f76696465732b612b666c657869626c652b616e642b657874656e7369626c652b73686f7070696e672b636172742b73797374656d2e266465736372697074696f6e3d31266c6f676f3d687474707325334125324625324675706c6f61642e77696b696d656469612e6f726725324677696b697065646961253246636f6d6d6f6e732532467468756d622532463925324639612532464c61726176656c2e7376672532463132303070782d4c61726176656c2e7376672e706e67266e616d653d31266f776e65723d31267061747465726e3d5369676e616c267468656d653d4c69676874)](https://camo.githubusercontent.com/5e5c2396ff1936278762f026ef0075fff20ce3ef11d3a1b667573abc23b05ba0/68747470733a2f2f736f6369616c6966792e6769742e63692f6e68616e636861756b702f6c617261636172742f696d6167653f637573746f6d5f6465736372697074696f6e3d4c617261436172742b69732b612b4c61726176656c2b7061636b6167652b746861742b70726f76696465732b612b666c657869626c652b616e642b657874656e7369626c652b73686f7070696e672b636172742b73797374656d2e266465736372697074696f6e3d31266c6f676f3d687474707325334125324625324675706c6f61642e77696b696d656469612e6f726725324677696b697065646961253246636f6d6d6f6e732532467468756d622532463925324639612532464c61726176656c2e7376672532463132303070782d4c61726176656c2e7376672e706e67266e616d653d31266f776e65723d31267061747465726e3d5369676e616c267468656d653d4c69676874)

LaraCart
========

[](#laracart)

[![Build Status](https://camo.githubusercontent.com/dac90e82a76b950382becdcfcce1b16f4f87f59b47acf7e5bfa0612cacf29885/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e68616e636861756b702f6c617261636172742f63692e796d6c3f6272616e63683d6d61696e)](https://camo.githubusercontent.com/dac90e82a76b950382becdcfcce1b16f4f87f59b47acf7e5bfa0612cacf29885/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e68616e636861756b702f6c617261636172742f63692e796d6c3f6272616e63683d6d61696e)[![License](https://camo.githubusercontent.com/70cccbbc38e64e0109fb46dc56f1458d29703aed09dec1a31fcbd1a3a7b8dbc4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e68616e636861756b702f6c61726163617274)](https://camo.githubusercontent.com/70cccbbc38e64e0109fb46dc56f1458d29703aed09dec1a31fcbd1a3a7b8dbc4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e68616e636861756b702f6c61726163617274)[![Downloads](https://camo.githubusercontent.com/6ce396d1059688b1e8c40c7d2d6719092ab096e9211193b5b05d38c688c86f75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e68616e636861756b702f6c61726163617274)](https://camo.githubusercontent.com/6ce396d1059688b1e8c40c7d2d6719092ab096e9211193b5b05d38c688c86f75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e68616e636861756b702f6c61726163617274)[![Contributors](https://camo.githubusercontent.com/3aa7bc3170bd0b370da3fd3d27fd1adca6e0f66ea8738a29da0e2fb1c0ce7656/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6e68616e636861756b702f6c61726163617274)](https://camo.githubusercontent.com/3aa7bc3170bd0b370da3fd3d27fd1adca6e0f66ea8738a29da0e2fb1c0ce7656/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6e68616e636861756b702f6c61726163617274)[![PHP Version Require](https://camo.githubusercontent.com/b2a09a4235a20c4971e582ff57b042e6fccdb00ed73e7c12e134f54f709d93cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e68616e636861756b702f6c61726163617274)](https://camo.githubusercontent.com/b2a09a4235a20c4971e582ff57b042e6fccdb00ed73e7c12e134f54f709d93cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e68616e636861756b702f6c61726163617274) [![Packagist Version](https://camo.githubusercontent.com/6a142546b0bb43629fcd9adda758a632a2c056ee4e9b033681f1cfcd52d7e2a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e68616e636861756b702f6c61726163617274)](https://camo.githubusercontent.com/6a142546b0bb43629fcd9adda758a632a2c056ee4e9b033681f1cfcd52d7e2a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e68616e636861756b702f6c61726163617274)

LaraCart is a Laravel package that provides a flexible and extensible shopping cart system. It supports multiple storage drivers (e.g., database, session) and offers a wide range of features for managing shopping carts in your Laravel application.

Features
--------

[](#features)

- Multiple storage drivers (Database, Session)
- Add, update, and remove items from the cart
- Support for polymorphic itemable models
- Discount management
- Assign carts to users
- Clear and count items in the cart
- Retrieve cart totals and quantities

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

[](#installation)

1. Install the package via Composer:

    ```
    composer require nhanchaukp/laracart
    ```
2. Publish the configuration and migration files:

    ```
    # config
    php artisan vendor:publish --provider="NhanChauKP\LaraCart\Providers\LaraCartServiceProvider" --tag=laracart-config

    #migrations
    php artisan vendor:publish --provider="NhanChauKP\LaraCart\Providers\LaraCartServiceProvider" --tag=laracart-migrations
    ```
3. Run the migrations:

    ```
    php artisan migrate
    ```
4. Configure the driver in `config/laracart.php` (default: `database`).

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

#### Add an Item to the Cart

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

```
use NhanChauKP\LaraCart\Facades\LaraCart;

$item = Product::find(1); // Example item
LaraCart::addItem($item, 2, 100.00, ['color' => 'red']);
```

#### Retrieve the Cart

[](#retrieve-the-cart)

```
$cart = LaraCart::getCart();
```

#### Get All Items

[](#get-all-items)

```
$items = LaraCart::getItems();
```

#### Remove an Item

[](#remove-an-item)

```
LaraCart::removeItem($item);
```

#### Clear the Cart

[](#clear-the-cart)

```
LaraCart::clear();
```

### Advanced Features

[](#advanced-features)

#### Set a Discount

[](#set-a-discount)

```
LaraCart::setDiscount(10); // 10% discount
```

#### Assign Cart to a User

[](#assign-cart-to-a-user)

```
LaraCart::assignToUser($userId);
```

#### Switch Drivers

[](#switch-drivers)

```
LaraCart::driver('session');
```

Configuration
-------------

[](#configuration)

The configuration file `config/laracart.php` allows you to customize the following:

- `driver`: The storage driver (`database` or `session`).
- `session_key`: The session key for the session driver.
- `currency`: The default currency.
- `models`: Custom models for `Cart` and `CartItem`.
- `cookie`: Cookie settings for guest users.

Models
------

[](#models)

### Cart

[](#cart)

The `Cart` model represents a shopping cart and includes the following attributes:

- `user_id`: The ID of the user associated with the cart.
- `session_id`: The session ID for guest users.
- `discount_percent`: The discount percentage applied to the cart.
- `total`: The total price of the cart.

### CartItem

[](#cartitem)

The `CartItem` model represents an item in the cart and includes the following attributes:

- `cart_id`: The ID of the cart.
- `itemable`: Polymorphic relation to the itemable model.
- `quantity`: The quantity of the item.
- `price`: The price of the item.
- `options`: Additional options for the item.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance62

Regular maintenance activity

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~48 days

Total

5

Last Release

242d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16833818?v=4)[Châu Thái Nhân](/maintainers/nhanchaukp)[@nhanchaukp](https://github.com/nhanchaukp)

---

Top Contributors

[![nhanchaukp](https://avatars.githubusercontent.com/u/16833818?v=4)](https://github.com/nhanchaukp "nhanchaukp (13 commits)")

---

Tags

laravelshoppingLaravel shopping cartLaravel cartlaravel shoppinglaracart

### Embed Badge

![Health badge](/badges/nhanchaukp-laracart/health.svg)

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

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k322.4k1](/packages/cybercog-laravel-love)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

438834.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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