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

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

hcart/laravel-multi-cart
========================

A flexible, extensible shopping cart solution for Laravel applications with multiple cart instances and configurable storage providers

10[6 PRs](https://github.com/mohamedhabibwork/laravel-multi-cart/pulls)PHPCI passing

Since Aug 20Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (7)Used By (0)

Laravel Multi-Cart Package
==========================

[](#laravel-multi-cart-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/165e5964511c447e355718b6f6b63f003ea3c120e5f48fca41b619f9f5501811/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68636172742f6c61726176656c2d6d756c74692d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hcart/laravel-multi-cart)[![GitHub Tests Action Status](https://camo.githubusercontent.com/fa68720963e7c3106754c56b47e756a85faee028315b837b441838b84d5e4f08/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68636172742f6c61726176656c2d6d756c74692d636172742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/hcart/laravel-multi-cart/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/9ae144e49c30fa0fe444abe2ac16934cb111c72f0dd8ee9cca3de163ed0e1ca3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68636172742f6c61726176656c2d6d756c74692d636172742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/hcart/laravel-multi-cart/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/368c9610466616ff0c53385943164f3dcd069b48f2edf559c98f98a930760be4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68636172742f6c61726176656c2d6d756c74692d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hcart/laravel-multi-cart)

A flexible, extensible shopping cart solution for Laravel applications that supports multiple cart instances with configurable storage providers. Built for Laravel v11+ and PHP 8.2+, it leverages modern Laravel features including polymorphic relationships and JSON configuration storage.

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

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
- [User Integration](#user-integration)
- [Cartable Items](#cartable-items)
- [CartProvider Enum](#cartprovider-enum)
- [Storage Providers](#storage-providers)
- [Enhanced Provider Conversion](#enhanced-provider-conversion)
- [Advanced Configuration](#advanced-configuration)
- [Events](#events)
- [Commands](#commands)
- [API Reference](#api-reference)
- [Examples](#examples)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Features
--------

[](#features)

- **Multiple Cart Instances**: Create and manage multiple named cart instances for different purposes (shopping, wishlist, favorites, etc.)
- **CartProvider Enum**: Type-safe provider selection with `CartProvider::SESSION`, `CartProvider::DATABASE`, etc.
- **Configurable Storage Providers**: Choose from session, cache, database, Redis, or file storage providers
- **Enhanced Provider Conversion**: Advanced `convertToProvider()` with automatic user association and cart merging
- **Polymorphic Relationships**: Add any Eloquent model to carts with full relationship support
- **JSON Configuration Storage**: Flexible configuration with JSON/JSONB support for enhanced flexibility
- **Soft Delete Support**: Built-in soft delete functionality with `deleted_at` timestamps for data recovery
- **Type-Safe Implementation**: Modern PHP 8.2+ features with strict typing and comprehensive interfaces
- **Comprehensive Event System**: Listen to cart creation, updates, deletions, and item changes
- **Built-in Validation**: Automatic validation and error handling with custom exceptions
- **Trait Support**: Easy integration with User models and cartable items using Laravel traits
- **Automatic Cleanup**: Scheduled cleanup of expired carts with configurable retention policies
- **Custom Callbacks**: Extensible callback system for item uniqueness, updates, and removals
- **Provider Migration**: Seamless migration between different storage providers with merging support
- **Performance Optimized**: Efficient caching strategies and optimized database queries

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

[](#requirements)

- **Laravel Framework**: v11.0+
- **PHP Version**: 8.2+
- **Database**: MySQL 8.0+, PostgreSQL 13+, SQLite 3.35+
- **Cache Drivers**: Redis, Memcached, File, Database
- **Session Drivers**: File, Cookie, Database, APC, Memcached, Redis

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

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require hcart/laravel-multi-cart
```

### Step 2: Publish Configuration

[](#step-2-publish-configuration)

```
php artisan vendor:publish --tag="laravel-multi-cart-config"
```

### Step 3: Database Setup (Optional)

[](#step-3-database-setup-optional)

If you plan to use the database provider, publish and run the migrations:

```
php artisan cart:publish-migrations
php artisan migrate
```

### Step 4: Environment Configuration

[](#step-4-environment-configuration)

Add these environment variables to your `.env` file:

```
LARAVEL_MULTI_CART_PROVIDER=session
LARAVEL_MULTI_CART_TAX_RATE=0.08
LARAVEL_MULTI_CART_CURRENCY=USD
```

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

[](#configuration)

The configuration file `config/laravel-multi-cart.php` allows extensive customization:

```
