PHPackages                             rariteth/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rariteth/laravel-cart

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

rariteth/laravel-cart
=====================

Laravel Shopping Cart

v0.13(2y ago)18121MITPHPPHP ^8.0|^7.1.3

Since Oct 8Pushed 2y agoCompare

[ Source](https://github.com/rariteth/laravel-cart)[ Packagist](https://packagist.org/packages/rariteth/laravel-cart)[ RSS](/packages/rariteth-laravel-cart/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (7)Versions (36)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6d574f5d0baf50219b4a5e4ade4dc1840f98692670d740eade8c30b058d7fb65/68747470733a2f2f7472617669732d63692e6f72672f72617269746574682f6c61726176656c2d636172742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rariteth/laravel-cart)[![Latest Stable Version](https://camo.githubusercontent.com/8262d32b06b0851daa4ef15077be829ddc0d23bec0dd5e7a11e4cb86810ebbd0/68747470733a2f2f706f7365722e707567782e6f72672f72617269746574682f6c61726176656c2d636172742f762f737461626c65)](https://packagist.org/packages/rariteth/laravel-cart)[![Total Downloads](https://camo.githubusercontent.com/b7d22b1fcc988c6d8d8a0f74939d32e1c99fcf9df297a80a4167a776433bbca3/68747470733a2f2f706f7365722e707567782e6f72672f72617269746574682f6c61726176656c2d636172742f646f776e6c6f616473)](https://packagist.org/packages/rariteth/laravel-cart)[![License](https://camo.githubusercontent.com/43decd3f332ce272a390fa322f38f653009b6302059762a2e109c30e9027b6ba/68747470733a2f2f706f7365722e707567782e6f72672f72617269746574682f6c61726176656c2d636172742f6c6963656e7365)](https://packagist.org/packages/rariteth/laravel-cart)

- [Installation](#installation)
- [Configuration](#configuration)
- [Instances](#instances)
- [Models](#models)
- [Database](#database)
- [Events](#events)
- [Example](#example)

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

[](#installation)

Install the package through [Composer](http://getcomposer.org/).

Run the Composer require command from the Terminal:

```
composer require rariteth/laravel-cart

```

If you're using Laravel 5.5, this is all there is to do.

Now you're ready to start using the laravel-cart in your application.

### Configuration

[](#configuration)

To save cart into the database so you can retrieve it later, the package needs to know which database connection to use and what the name of the table is. By default the package will use the default database connection and use a table named `laravel-cart`. If you want to change these options, you'll have to publish the `config` file.

```
php artisan vendor:publish --provider="Rariteth\LaravelCart\CartServiceProvider" --tag="laravel-cart-config"

```

This will give you a `cart.php` config file in which you can make the changes.

To make your life easy, the package also includes a ready to use `migration` which you can publish by running:

```
php artisan vendor:publish --provider="Rariteth\LaravelCart\CartServiceProvider" --tag="migrations"

```

This will place a `laravel-cart` table's migration file into `database/migrations` directory. Now all you have to do is run `php artisan migrate` to migrate your database.

### Instances

[](#instances)

For using many instances like 'wishlist', 'some-other-items' and etc... Inject in container the CartInstance with params 'instanceName' and 'guardName'

```
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Instance 'whishlist' with guard 'web'
        $this->app
             ->when(
                [
                    Whishlist\ManageController::class,
                    Whishlist\CheckoutController::class
                ]
             )
             ->needs(CartRepositoryInterface::class)
                ->give(function () {
                    return new CartRepository(new CartInstance('whishlist', 'web'));
                });

        // Instance 'other-cart' with guard 'frontend'
        $this->app
             ->when(OtherCartController::class)
             ->needs(CartInstanceInterface::class)
             ->give(function () {
                return new CartInstance('other-cart', 'frontend');
             });

...
```

### Models

[](#models)

All products most implements BuyableInterface

### Example

[](#example)

```
    class CartController extends Controller
    {
        /**
         * @var CartRepositoryInterface
         */
        private $cartRepository;

        /**
         * CartController constructor.
         *
         * @param CartRepositoryInterface $cartRepository
         */
        public function __construct(CartRepositoryInterface $cartRepository)
        {
            $this->cartRepository = $cartRepository;
        }

        /**
         * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
         */
        public function index()
        {
            $items = $this->cartRepository->getItems();

            return view('cart.index', compact('items'));
        }

        /**
         * @param Product $product
         *
         * @return \Illuminate\Http\RedirectResponse
         */
        public function add(Product $product)
        {
            $qty = 1;
            $this->cartRepository->add($product, $qty);

            return redirect()->route('cart.index');
        }

        /**
        * @return \Illuminate\Http\RedirectResponse
        */
        public function clear()
        {
           $this->cartRepository->clear();

           return redirect()->route('cart.index');
        }

        /**
        * @param string $rowId
        *
        * @return \Illuminate\Http\RedirectResponse
        */
        public function remove(string $rowId)
        {
           if ($cartItem = $this->cartRepository->get($rowId)) {
               $this->cartRepository->remove($cartItem);

               return redirect()->route('cart.index');
           }

           return abort(404);
        }

        /**
        * @param string $rowId
        * @param int    $qty
        *
        * @return \Illuminate\Http\RedirectResponse
        */
        public function updateQty(string $rowId, int $qty)
        {
           if ($cartItem = $this->cartRepository->get($rowId)) {

               $cartItem->setQty($qty);
               $this->cartRepository->update($cartItem);

               return redirect()->route('cart.index');
           }

           return abort(404);
        }

        /**
         * @param CartRepositoryInterface $cartRepository
         */
        public function refreshCartItems(CartRepositoryInterface $cartRepository): void
        {
            $shouldRefreshItems = $cartRepository->search(function (CartItem $cartItem) {
                return $this->shouldRefreshCartItem($cartItem);
            });

            $cartRepository->refresh($shouldRefreshItems);
        }

        /**
         * @param CartRepositoryInterface $cartRepository
         */
        public function refreshCartItems(CartRepositoryInterface $cartRepository): void
        {
            $shouldRefreshItems   = $cartRepository->getGuestItems();

            $cartRepository->refresh($shouldRefreshItems);
        }

        /**
         * @param CartRepositoryInterface $cartRepository
         */
        public function removeOldCartItems(CartRepositoryInterface $cartRepository): void
        {
            $itemsForRemove = $cartRepository->search(function (CartItem $cartItem) {
                return $this->shouldRemoveCartItem($cartItem);
            });

            $cartRepository->removeBatch($itemsForRemove);
        }

        /**
         * @param CartItem $cartItem
         *
         * @return bool
         */
        private function shouldRefreshCartItem(CartItem $cartItem): bool
        {
            return $cartItem->updatedAt < $this->expireAt()->subDay();
        }

        /**
         * @param CartItem $cartItem
         *
         * @return bool
         */
        private function shouldRemoveCartItem(CartItem $cartItem): bool
        {
            return $cartItem->addedAt < now()->subDays(5);
        }
    }
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

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

Recently: every ~234 days

Total

35

Last Release

1086d ago

PHP version history (3 changes)v0.9.2PHP ^7.1.3

v0.10.1PHP ^7.2

v0.11PHP ^8.0|^7.1.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/204567?v=4)[rariteth](/maintainers/rariteth)[@rariteth](https://github.com/rariteth)

---

Top Contributors

[![rariteth](https://avatars.githubusercontent.com/u/204567?v=4)](https://github.com/rariteth "rariteth (43 commits)")

---

Tags

laravelcartshoppingcart

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rariteth-laravel-cart/health.svg)

```
[![Health](https://phpackages.com/badges/rariteth-laravel-cart/health.svg)](https://phpackages.com/packages/rariteth-laravel-cart)
```

###  Alternatives

[gloudemans/shoppingcart

Laravel Shoppingcart

3.7k756.7k12](/packages/gloudemans-shoppingcart)[bumbummen99/shoppingcart

Laravel Shoppingcart

518555.4k3](/packages/bumbummen99-shoppingcart)[olimortimer/laravelshoppingcart

Laravel Shoppingcart

4343.2k](/packages/olimortimer-laravelshoppingcart)

PHPackages © 2026

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