PHPackages                             binafy/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. [Framework](/categories/framework)
4. /
5. binafy/laravel-cart

ActiveLibrary[Framework](/categories/framework)

binafy/laravel-cart
===================

Laravel Cart is a customizable package for adding shopping cart functionality to Laravel applications

v2.0.0(7mo ago)40445.9k↓27.7%20MITPHPPHP ^8.0CI passing

Since Jun 4Pushed 7mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (19)Used By (0)

Laravel Cart
============

[](#laravel-cart)

[![binafy-laravel-cart](https://camo.githubusercontent.com/1729889ce088dca372953a72cb59e93b49dcf24d4bd67a46263988f13d28a61b/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230436172742e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6166792532466c61726176656c2d63617274267061747465726e3d617574756d6e267374796c653d7374796c655f31266465736372697074696f6e3d637573746f6d697a61626c652b7061636b6167652b666f722b616464696e672b73686f7070696e672b636172742b66756e6374696f6e616c6974792b746f2b4c61726176656c2b6170706c69636174696f6e73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/1729889ce088dca372953a72cb59e93b49dcf24d4bd67a46263988f13d28a61b/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230436172742e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6166792532466c61726176656c2d63617274267061747465726e3d617574756d6e267374796c653d7374796c655f31266465736372697074696f6e3d637573746f6d697a61626c652b7061636b6167652b666f722b616464696e672b73686f7070696e672b636172742b66756e6374696f6e616c6974792b746f2b4c61726176656c2b6170706c69636174696f6e73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![PHP Version Require](https://camo.githubusercontent.com/2f17793a9d79dc7fb1aee89eeca9984d75a7cb5e6f2e5ca9edf6be23f7da87b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f62696e6166792f6c61726176656c2d636172742f7068702e737667)](https://packagist.org/packages/binafy/laravel-cart)[![Latest Stable Version](https://camo.githubusercontent.com/f7fd568d1da7fd87d3242801167a575a2715aae7235ef7749062a45e56113917/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696e6166792f6c61726176656c2d636172742e737667)](https://packagist.org/packages/binafy/laravel-cart)[![Total Downloads](https://camo.githubusercontent.com/69faa7a75421215e69c0ebce80896249babf7ee3848a8761d921271a785b9a44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62696e6166792f6c61726176656c2d636172742e737667)](https://packagist.org/packages/binafy/laravel-cart)[![License](https://camo.githubusercontent.com/ad0e18e1fcfdcc37afb294c6eb1563b728fa9189f354c432866e82f09ee3d40f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62696e6166792f6c61726176656c2d636172742e737667)](https://packagist.org/packages/binafy/laravel-cart)[![Passed Tests](https://github.com/binafy/laravel-cart/actions/workflows/tests.yml/badge.svg)](https://github.com/binafy/laravel-cart/actions/workflows/tests.yml)

- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Publish](#publish)
- [Usage](#usage)
    - [Configuration](#configuration)
        - [User Configuration](#user-configuration)
    - [Laravel Cart Facade](#laravel-cart-facade)
        - [Driver](#driver)
        - [Support Drivers](#support-drivers)
    - [Laravel Cart Model](#laravel-cart-model)
        - [Store Cart](#store-cart)
        - [Access Itemable](#access-itemable)
        - [Create Cart With Storing Items](#create-cart-with-storing-item)
        - [Store multiple items](#store-multiple-items)
        - [Store Item For a Cart](#store-item-for-a-cart)
        - [Delete Item From Cart](#delete-item-from-cart)
        - [Delete All Items From Cart](#delete-all-items-from-cart)
        - [Increase Quantity](#increase-quantity)
        - [Decrease Quantity](#decrease-quantity)
    - [Available Events](#available-events)
- [Contributors](#contributors)
- [Security](#security)
- [Changelog](#changelog)
- [License](#license)
- [Donate](#donate)

Introduction
------------

[](#introduction)

The `Laravel Cart` is a highly customizable and flexible package that integrates basket functionality into your Laravel application. It simplifies storing and managing cart items, supporting multiple item types and quantities. It is ideal for e-commerce platforms to create carts, attach items, and manage them efficiently. Installation is straightforward via Composer, and it offers robust features like secure item storage, easy cart manipulation, and seamless integration with your existing Laravel app.

Features
--------

[](#features)

The `Laravel Cart` package is an ideal choice for developers looking to implement a reliable and scalable cart system in their Laravel-based e-commerce applications:

- Item Management: Easily add, update, and remove items from the cart with an intuitive API.
- Attributes and Options: Define custom attributes and options for cart items to handle variations like size and color.
- Tax Calculation: Built-in support for tax calculations, enabling automatic tax application based on predefined rules.
- Discounts and Coupons: Integrate discount codes and coupon functionalities to offer promotions and special offers to customers.
- Session and Database Storage: Flexible storage options allow carts to be stored in sessions or the database.
- Events and Listeners: Hook into various cart events with listeners to perform actions like logging or triggering additional business logic.
- Customizable: Extend and customize the core functionalities to meet specific business requirements.
- Easy Integration: Designed to integrate seamlessly with existing Laravel projects, providing a smooth development experience.

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

[](#installation)

You can install the package with Composer:

```
composer require binafy/laravel-cart
```

Publish
-------

[](#publish)

If you want to publish a config file, you can use this command:

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

If you want to publish the migrations, you can use this command:

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

For convenience, you can use this command to publish config, migration, and ... files:

```
php artisan vendor:publish --provider="Binafy\LaravelCart\Providers\LaravelCartServiceProvider"
```

After publishing, run the `php artisan migrate` command.

Usage
-----

[](#usage)

### Configuration

[](#configuration)

You can config the `Laravel Cart` with `laravel-cart.php` config that exists in `config` folder.

#### User Configuration

[](#user-configuration)

If you are using `uuid` or `ulid`, you can change `foreign_key_type` to your correct foreign key type:

```
'users' => [
    ...

    /*
     * Specify the type of foreign key being used (e.g., 'id', 'uuid', 'ulid').
     * For non-standard IDs, make sure to add the relevant traits to your models.
     */
    'foreign_key_type' => 'id', // Options: uuid, ulid, id
],
```

### Laravel Cart Facade

[](#laravel-cart-facade)

For convenience, you can use Laravel Cart facade to store, delete, and ...:

```
