PHPackages                             al-mamun-devops/laravel-shopping-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. al-mamun-devops/laravel-shopping-cart

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

al-mamun-devops/laravel-shopping-cart
=====================================

Lightweight shopping cart for Laravel 12 using session or filesystem (no DB)

v1.0.0-alpha(6mo ago)01MITPHP

Since Oct 23Pushed 6mo agoCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

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

[](#-laravel-shopping-cart)

A lightweight and reusable **shopping cart package** for **Laravel 12+**, designed for developers who want to add cart functionality without needing a database. This package uses **Session** or **File Storage** for managing cart data.

---

🚀 Features
----------

[](#-features)

- ✅ Works with **Laravel 12+**
- 🧠 No database required
- 🗃️ Storage options: **Session** or **File system**
- 🔧 Simple API for adding, updating, removing, and clearing items
- 💰 Automatic cart total and item count calculation
- 📦 Easy to install and integrate into any Laravel project

---

📦 Installation
--------------

[](#-installation)

### 1. Add the package via Composer (local or from GitHub)

[](#1-add-the-package-via-composer-local-or-from-github)

```
composer require al-mamun-devops/laravel-shopping-cart
```

### 2. Publish configuration file

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

```
php artisan vendor:publish --tag=config --provider="AlMamunDevOps\ShoppingCart\ShoppingCartServiceProvider"
```

This will publish `config/shoppingcart.php` where you can choose storage type:

```
return [
    'storage' => env('SHOPPINGCART_STORAGE', 'session'), // or 'file'
    'file_path' => storage_path('app/shopping_cart.json'),
];
```

---

⚙️ Configuration
----------------

[](#️-configuration)

You can choose between **Session** and **File Storage**:

OptionDescription`session`Stores cart data in the Laravel session. Default option.`file`Persists cart data in a JSON file under `storage/app/shopping_cart.json`.Set your preferred option in the `.env` file:

```
SHOPPINGCART_STORAGE=session
```

---

🧰 Usage
-------

[](#-usage)

Use the Cart Facade to manage cart operations:

```
use Cart;

// Add products
Cart::add(1, 'Laptop', 1000, 2);
Cart::add(2, 'Mouse', 300, 1);

// Update quantity
Cart::update(1, 5);

// Remove item
Cart::remove(2);

// Get all items
$items = Cart::all();

// Get total amount
$total = Cart::total();

// Get total count
$count = Cart::count();

// Clear cart
Cart::clear();
```

---

🧩 Example Controller
--------------------

[](#-example-controller)

```
