PHPackages                             lutforrahman/nujhatcart - 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. lutforrahman/nujhatcart

ActivePackage

lutforrahman/nujhatcart
=======================

Nujhatcart The Laravel Shoppingcart

5.4.1(8y ago)81.8k5[1 issues](https://github.com/contactlutforrahman/nujhatcart/issues)MITPHPPHP &gt;=5.4.0

Since Aug 6Pushed 8y ago5 watchersCompare

[ Source](https://github.com/contactlutforrahman/nujhatcart)[ Packagist](https://packagist.org/packages/lutforrahman/nujhatcart)[ RSS](/packages/lutforrahman-nujhatcart/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/530eacd901af5781694cc7085a4c093e01abf98beb9d04eff196fe37907055d5/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f762f737461626c65)](https://packagist.org/packages/lutforrahman/nujhatcart)[![Total Downloads](https://camo.githubusercontent.com/c96d54033d476ddcda3111ac0e7e5520b55b3d2f1e5bb88e080209997e4119c0/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f646f776e6c6f616473)](https://packagist.org/packages/lutforrahman/nujhatcart)[![Latest Unstable Version](https://camo.githubusercontent.com/88ff52114fa50fa1392cab67d87d6b84c343f32a9bd6f908b713532a9af52e25/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f762f756e737461626c65)](https://packagist.org/packages/lutforrahman/nujhatcart)[![License](https://camo.githubusercontent.com/5a5df019ae1141caab63c95c46a144f0ea5973c9bfd87616dd3e65ed943ab479/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f6c6963656e7365)](https://packagist.org/packages/lutforrahman/nujhatcart)

[![Monthly Downloads](https://camo.githubusercontent.com/7b97cf58fb117eb182aa3d167b6740b66373c48153d1fa99f5e109bb9528e012/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f642f6d6f6e74686c79)](https://packagist.org/packages/lutforrahman/nujhatcart)

[![Daily Downloads](https://camo.githubusercontent.com/c024c8a382784f36acbed52ea0dc5dcbbdab61cc9a494e1cce6b67c9a89b7c86/68747470733a2f2f706f7365722e707567782e6f72672f6c7574666f727261686d616e2f6e756a686174636172742f642f6461696c79)](https://packagist.org/packages/lutforrahman/nujhatcart)

Nujhatcart The Laravel Shoppingcart
===================================

[](#nujhatcart-the-laravel-shoppingcart)

A simple shoppingcart implementation for Laravel &gt;=5.4

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

[](#installation)

### Laravel 5.4

[](#laravel-54)

Install the package through [Composer](http://getcomposer.org/). Open your terminal in your project directory, wirte :

```
composer require lutforrahman/nujhatcart
```

Press enter and package will start downloading ...

OR

Edit your project's `composer.json` file and add :

```
"require": {
	"laravel/framework": "5.4.*",
	"lutforrahman/nujhatcart": "5.4"
}
```

Next, run the Composer update command from the Terminal:

```
composer update

```

Now all you have to do is add the service provider of the package and alias the package. To do this open your `config/app.php` file.

Add a new line to the `service providers` array:

```
Lutforrahman\Nujhatcart\NujhatcartServiceProvider::class

```

After that add a new line to the `aliases` array:

```
'Cart' => Lutforrahman\Nujhatcart\Facades\Cart::class,

```

Now you're ready to start using the shoppingcart in your application.

Documentation
-------------

[](#documentation)

Look at one of the following topics to learn more about iLaCart

### Add to Cart

[](#add-to-cart)

The shoppingcart gives you the following methods to use:

**Cart::insert()**

```
	/**
     * Add a row to the cart
     * @param string|array $id Unique ID of the item|Item formated as array|Array of items
     * @param string $sku Unique SKU of the item
     * @param string $name Name of the item
     * @param string $slug Slug of the item
     * @param string $image Image of the item
     * @param string $description Description of the item
     * @param int $quantity Item quantity to add to the cart
     * @param float $price Price of one item
     * @param float $discount Discount amount of one item
     * @param float $tax Tax amount of one item
     * @param array $options Array of additional options, such as 'size' or 'color'
     */

$product = Product::find($id);
$item = [
	'id' => $product->id,
	'sku' => $product->sku,
	'name' => $product->name,
	'slug' => $product->slug,
	'image' => $product->thumbnail,
	'description' => $product->description,
	'quantity' => $quantity > 0 ? $quantity : 1,
	'price' => $product->price,
	'discount' => $product->discount_amount,
	'tax' => 0,
	'options' => array('size' => 'M', 'color' => 'White')
];
Cart::insert($item);

// Insert multiple arry()

$product = Product::find($id);
$item = [
	'id' => $product->id,
	'sku' => $product->sku,
	'name' => $product->name,
	'slug' => $product->slug,
	'image' => $product->thumbnail,
	'description' => $product->description,
	'quantity' => $quantity > 0 ? $quantity : 1,
	'price' => $product->price,
	'discount' => $product->discount_amount,
	'tax' => 0,
	'options' => array('size' => 'M', 'color' => 'White')
];

$product2 = Product::find($id2);
$item2 = [
	'id' => $product2->id,
	'sku' => $product2->sku,
	'name' => $product2->name,
	'slug' => $product2->slug,
	'image' => $product2->thumbnail,
	'description' => $product2->description,
	'quantity' => $product2 > 0 ? $quantity : 1,
	'price' => $product2->price,
	'discount' => $product2->discount_amount,
	'tax' => 0,
	'options' => array('size' => 'M', 'color' => 'White')
];

Cart::insert(array($item, $item2));

```

### Update Cart

[](#update-cart)

**Cart::update()**

```
/**
 * Update the quantity of one row of the cart
 *
 * @param  string        $rowId       The rowid of the item you want to update
 * @param  integer|Array $attribute   New quantity of the item|Array of attributes to update
 * @return boolean
 */

 $rowId = 'feeb69e1a11765b136a0de76c2baaa40';

Cart::update($rowId, 4);

OR

Cart::update($rowId, array('name' => 'Product name'));

OR

$product = Product::find($id);

$item = [
	'id' => $product->id,
	'sku' => $product->sku,
	'name' => $product->name,
	'slug' => $product->slug,
	'image' => $product->thumbnail,
	'description' => $product->description,
	'quantity' => $quantity > 0 ? $quantity : 1,
	'price' => $product->price,
	'discount' => $product->discount_amount,
	'tax' => 0,
	'options' => array('size' => 'M', 'color' => 'White')
];
Cart::update($rowId, $item);

```

// In Controller

```
	public function updateCart($rowId){

		$item = [
			'quantity' => 3,
			'discount' => 9,
			'tax' => 9.5,
			'options' => array('size' => 'M', 'color' => 'White')
		];
		Cart::update($rowId, $item);

		return Cart::contents();

	}
```

### Remove an Item from Cart

[](#remove-an-item-from-cart)

**Cart::remove()**

```
/**
 * Remove a row from the cart
 *
 * @param  string  $rowId The rowid of the item
 * @return boolean
 */

 $rowId = 'feeb69e1a11765b136a0de76c2baaa40';

Cart::remove($rowId);
```

// In Controller

```
	public function removeCart($rowId){
		Cart::remove($rowId);
		return Cart::contents();
	}
```

### Get a single Item from Cart

[](#get-a-single-item-from-cart)

**Cart::get()**

```
/**
 * Get a row of the cart by its ID
 *
 * @param  string $rowId The ID of the row to fetch
 * @return CartRowCollection
 */

$rowId = 'feeb69e1a11765b136a0de76c2baaa40';

Cart::get($rowId);
```

### Get all Items from Cart

[](#get-all-items-from-cart)

**Cart::contents()**

```
/**
 * Get the cart content
 *
 * @return CartCollection
 */

Cart::contents();
```

### Empty Cart \[ remove all items from cart\]

[](#empty-cart--remove-all-items-from-cart)

**Cart::destroy()**

```
/**
 * Empty the cart
 *
 * @return boolean
 */

Cart::destroy();
```

### Get total amount of added Items in Cart

[](#get-total-amount-of-added-items-in-cart)

**Cart::total()**

```
/**
 * Total amount of cart
 *
 * @return float
 */

Cart::total();
```

### \[Subtotal\] Get total amount of an added Item in Cart \[single item with quantity &gt; 1\]

[](#subtotal-get-total-amount-of-an-added-item-in-cart-single-item-with-quantity--1)

**Cart::subtotal()**

```
/**
 * Sub total amount of cart
 *
 * @return float
 */

Cart::subtotal();
```

### Get total discount amount of items added in Cart

[](#get-total-discount-amount-of-items-added-in-cart)

**Cart::discount()**

```
/**
 * Discount of cart
 *
 * @return float
 */

Cart::discount();
```

**Cart::setCustomDiscount(5.00)**

```
/**
 * @param $amount
 * @return bool
 */

Cart::setCustomDiscount(5.00);
```

**Cart::customDiscount()**

```
/**
 * Custom discount of cart
 *
 * @return float
 */

Cart::customDiscount();
```

### Get total quantity of a single item added in Cart

[](#get-total-quantity-of-a-single-item-added-in-cart)

**Cart::cartQuantity()**

```
/**
 * Get the number of items in the cart
 *
 * @param  boolean $totalItems Get all the items (when false, will return the number of rows)
 * @return int
 */

 Cart::cartQuantity();      // Total items
 Cart::cartQuantity(false); // Total rows

```

### Show Cart contents

[](#show-cart-contents)

```
foreach(Cart::contents() as $item)
{
	echo " " . ' Name : ' . $item->name . ' Price : ' . $item->price . ' Size : ' . $item->options->size;
}
```

### Exceptions

[](#exceptions)

The Cart package will throw exceptions if something goes wrong. This way it's easier to debug your code using the Cart package or to handle the error based on the type of exceptions. The Cart packages can throw the following exceptions:

ExceptionReason*NujhatcartInstanceException*When no instance is passed to the instance() method*NujhatcartInvalidItemException*When a new product misses one of it's arguments (`id`, `name`, `quantity`, `price`, `tax`)*NujhatcartInvalidDiscountException*When a non-numeric discount is passed*NujhatcartInvalidPriceException*When a non-numeric price is passed*NujhatcartInvalidQuantityException*When a non-numeric quantity is passed*NujhatcartInvalidItemIDException*When the `$itemId` that got passed doesn't exists in the current cart*NujhatcartInvalidTaxException*When a non-numeric tax is passed*NujhatcartUnknownModelException*When an unknown model is associated to a cart rowExample
-------

[](#example)

// Controller

```
	/**
     * Display the specified resource.
     *
     * @param int $id
     * @param int $quantity
     * @param string $size
     * @param string $color
     * @return \Illuminate\Http\Response
     */
    public function storeCart($id, $quantity, $size, $color)
    {
        $product = Product::find($id);
        $item = [
            'id' => $product->id,
            'sku' => $product->sku,
            'name' => $product->name,
            'slug' => $product->slug,
            'image' => $product->thumbnail,
            'description' => $product->description,
            'quantity' => $quantity > 0 ? $quantity : 1,
            'price' => $product->price,
            'discount' => $product->discount_amount,
            'tax' => 0,
			'options' => ['size' => $size, 'color' => $color]
        ];
        Cart::insert($item);
        $items = Cart::contents();
        $quantity = Cart::cartQuantity();
        $total = Cart::total();
		return view('home', ['items' => $items, 'quantity' => $quantity, 'total' => $total]);
    }
```

// View

```

           	Product
           	Quantity
           	Item Price
           	Discount
           	Subtotal

   	@foreach(Cart::contents() as $item)

               	{{ $item->name }}
               	{{ $item->options->has('size') ? $item->options->size : '' }}
               	{{ $item->options->has('color') ? $item->options->color : '' }}

           	${{ $item->price }}
           	${{ $item->discount }}
           	${{ $item->subtotal }}

   	@endforeach

```

Follow me
---------

[](#follow-me)

Follow me on twitter : [https://twitter.com/social\_lutfor](https://twitter.com/social_lutfor)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

3216d ago

Major Versions

1.0.2 → 5.3.02017-03-23

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

5.3.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/2caa0196ba8e1b581f79e0fe26e6a81fc6ab1d21acddd304b450679dad6bd1b3?d=identicon)[lutforrahman](/maintainers/lutforrahman)

---

Top Contributors

[![contactlutforrahman](https://avatars.githubusercontent.com/u/20427634?v=4)](https://github.com/contactlutforrahman "contactlutforrahman (14 commits)")

---

Tags

ecommerceshoppingcartlaravel-shoppingcartNujhatcart

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lutforrahman-nujhatcart/health.svg)

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

###  Alternatives

[gloudemans/shoppingcart

Laravel Shoppingcart

3.7k756.7k12](/packages/gloudemans-shoppingcart)[jlevers/selling-partner-api

PHP client for Amazon's Selling Partner API

4295.2M1](/packages/jlevers-selling-partner-api)[bumbummen99/shoppingcart

Laravel Shoppingcart

518555.4k3](/packages/bumbummen99-shoppingcart)[hardevine/shoppingcart

Laravel Shoppingcart

357614.3k4](/packages/hardevine-shoppingcart)[amsgames/laravel-shop

Package set to provide shop or e-commerce functionality (such as CART, ORDERS, TRANSACTIONS and ITEMS) to Laravel for customizable builds.

4845.9k](/packages/amsgames-laravel-shop)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)

PHPackages © 2026

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