PHPackages                             laravelir/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. laravelir/cart

ActiveLibrary

laravelir/cart
==============

shop cart package

0.1.0(3y ago)21MITPHPPHP &gt;=7.4|^8.0

Since Feb 27Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/laravelir/cart)[ Packagist](https://packagist.org/packages/laravelir/cart)[ Docs](https://github.com/miladimos/cart)[ Fund](https://github.com/laravelir/cart)[ GitHub Sponsors](https://github.com/cart)[ RSS](/packages/laravelir-cart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

- [![Starts](https://camo.githubusercontent.com/83b5c9494d7fd8056388726b9f58f34c9e4616f7991a4a20ccfa481383e3c762/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c61726176656c69722f636172743f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/laravelir/cart/forks)
- [![Forks](https://camo.githubusercontent.com/564e3eb11682c8c5d46a3a45abb41ff1eca3c3892c2a38d23f212f11b36ff736/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c61726176656c69722f636172743f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/laravelir/cart/stargazers)
- [![Total Downloads](https://camo.githubusercontent.com/8788cf8948f55eb364dfc145547ba587f231916102f0b42e25921d0e1080904e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c69722f636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelir/cart)

cart package (In Develop)
=========================

[](#cart-package-in-develop)

a multi driver shopping cart package

### Installation

[](#installation)

1. Run the command below to add this package:

```
composer require laravelir/cart

```

2. Open your config/app.php and add the following to the providers/aliases array:

```
Laravelir\Cart\Providers\CartServiceProvider::class,
```

```
'Cart' => Laravelir\Cart\Facade\Cart::class,
```

3. Run the command below to install package:

```
php artisan cart:install

```

### Drivers

[](#drivers)

Session - Cookie - Eloquent - Cache

you can set your favorite driver in config file

eloquent driver need to authenticated user for save user's id

### How to use

[](#how-to-use)

add `HasCart` trait to User model

this trait has one method:

```
$this->cart(); // return cart
```

#### Methods

[](#methods)

$cart = resolve(Cart());

$cart-&gt;all();

$cart-&gt;add();

$cart-&gt;has();

$cart-&gt;update();

$cart-&gt;count();

$cart-&gt;delete();

$cart-&gt;truncate();

#### Helpers

[](#helpers)

```
cart();

cartItems();
```

Cart::user($user\_id)-&gt;add(); Cart::driver('session')-&gt;add(); Cart::add(\['id' =&gt; '293ad', 'name' =&gt; 'Product 1', 'qty' =&gt; 1, 'price' =&gt; 9.99, 'options' =&gt; \['size' =&gt; 'large'\]\]);

#### Usage

[](#usage)

$user = auth()-&gt;user();

$product = Product::first();

$cart = resolve(Cart());

$data = \[ 'item' =&gt; $product, 'title' =&gt; $product-&gt;title, 'quantity' =&gt; 1, 'price' =&gt; $product-&gt;price, \];

$options = \[ 'color' =&gt; 'red', 'size' =&gt; 'XL' \]; $user-&gt;cart-&gt;add($data, $options);

$data = \[

\]; Cart::update($itemId, $data); Cart::update($itemId)-&gt;increaseQuantity(); Cart::update($itemId)-&gt;decreaseQuantity(); Cart::all(); Cart::count(); Cart::get($itemId); Cart::delete($itemId); Cart::truncate();

#### Cartable Contract

[](#cartable-contract)

For the convenience of faster adding items to cart and their automatic association, your model can implement Buyable interface. To do so, it must implement such functions:

```
