PHPackages                             mrnewport/laravel-stow - 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. mrnewport/laravel-stow

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

mrnewport/laravel-stow
======================

This unofficial laravel package allows for the addition of any model to an instancable "Cart", "Quote" or other "Basket".

v1.0.0(1y ago)12MITPHP

Since Jan 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MrNewport/laravel-stow)[ Packagist](https://packagist.org/packages/mrnewport/laravel-stow)[ RSS](/packages/mrnewport-laravel-stow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel Stow Package
====================

[](#laravel-stow-package)

Overview
--------

[](#overview)

Laravel Stow is an unofficial laravel package designed to handle the management of baskets and basket items within a Laravel application. It provides a flexible and extensible solution for handling shopping carts, wishlists, and other similar use cases. This package intentionally avoids pricing and checkout functionality for granularity purposes, focusing solely on the management of items within baskets. If you are looking for a qty based pricelist functionality, keep your eye out for mrnewport/price, my upcoming package.

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

[](#installation)

To integrate the Laravel Stow package into your Laravel project, execute:

```
composer require mrnewport/laravel-stow
```

Then, publish and migrate the database tables:

```
php artisan vendor:publish --provider="MrNewport\LaravelStow\StowProvider"
php artisan migrate
```

Configuration
-------------

[](#configuration)

Define basket instances and restrictions in `config/stow.php` to ensure type safety and integrity:

```
return [
    'instances' => [
        'cart' => [Product::class, Item::class],
        // Additional instances...
    ],
];
```

Instances not listed will remain unrestricted, accepting any `Stowable` models.

### Creating Baskets

[](#creating-baskets)

Instantiate a basket, specifying an optional type (instance name):

```
$cart = new Basket('cart'); // restricted to Product and Item (see stow.php config)
$wishlist = new Basket(); // Unrestricted, any item implementing Stowable interface
```

### Adding Items to Baskets

[](#adding-items-to-baskets)

Add Stowable interface to any models to allow them to be added to baskets:

```
class Product implements Stowable
{
    // ...
}
```

Add items respecting instance restrictions and options:

```
$product = new Product();
$cart->add($product, 1, ['size' => 'M', 'color' => 'blue']);

$item = new Item(); // Assume this class implements Stowable as well
$cart->add($item, 2);

// Service has not been explicitly allowed in the 'cart' instance (see stow.php config)
$service = new Service();
$cart->add($service); // Throws UnstowableObjectException

$wishlist->add($service); // instances without restrictions can accept any Stowable
```

Items that are already in the basket will have their quantities incremented only when the item exists with identical options.

```
$basketItem1 = $cart->add($product); // new product added because options don't match, quantity in cart is 1
$basketItem2->add($product, 3, ['size' => 'M', 'color' => 'blue']); // product with same options already in cart, quantity incremented and is now 3
```

### Updating Basket Items

[](#updating-basket-items)

Update item details within the basket, this requires the BasketItem or its ID:

```
$cart->change($basketItem, 3, ['size' => 'L']); // Update quantity and options
```

### Removing Items from Baskets

[](#removing-items-from-baskets)

Remove items from the basket by BasketItem or ID:

```
$cart->remove($basketItem);
```

### Retrieving Basket Items

[](#retrieving-basket-items)

Retrieve items from the basket:

```
$basketItems = $cart->basketItems->with('stowable')->get();

// group items by stowable type
$grouped = $basketItems->groupBy('stowable_type');

// filter items by stowable class
$filtered = $basketItems->filter(function($item) {
    return $item->stowable instanceof Product;
});

// iterate over items
foreach($basketItems as $basketItem) {
    $stowable = $basketItem->stowable;
    // ...
}
```

### Merging Baskets

[](#merging-baskets)

Merge the contents of one basket into another:

```
$wishlist->merge($cart);
```

### Clone Baskets

[](#clone-baskets)

Clone a basket and its associated items:

```
$clone = $wishlist->clone();
```

### Deleting Baskets

[](#deleting-baskets)

Delete a basket and its associated items:

```
$cart->delete();
```

Detailed Events Overview
------------------------

[](#detailed-events-overview)

Here's a look at the events, the objects they provide, and how they can be used:

### 1. BasketCreatedEvent

[](#1-basketcreatedevent)

- **Object Included**: `$basket` (The newly created basket instance)
- **Usage**: You can use this event to perform actions after a new basket has been created, such as logging, custom notifications, or integrating with other systems.

### 2. BasketUpdatedEvent

[](#2-basketupdatedevent)

- **Object Included**: `$basket` (The updated basket instance)
- **Usage**: This event allows you to respond to updates on a basket, enabling actions like auditing, triggering business workflows, or updating related data.

### 3. BasketDeletedEvent

[](#3-basketdeletedevent)

- **Object Included**: `$basket` (The deleted basket instance)
- **Usage**: Important for cleaning up related resources or performing actions post-deletion. The built-in listener uses this to remove associated basket items, but you can extend functionality to suit other needs.

### 4. BasketItemCreatedEvent

[](#4-basketitemcreatedevent)

- **Object Included**: `$basketItem` (The newly added basket item instance)
- **Usage**: Useful for tracking additions to the basket, updating inventory, or triggering recommendations based on new basket contents.

### 5. BasketItemUpdatedEvent

[](#5-basketitemupdatedevent)

- **Object Included**: `$basketItem` (The updated basket item instance)
- **Usage**: Leverage this event to handle changes in basket items, such as adjusting stock levels, recalculating basket totals, or applying additional business rules.

### 6. BasketItemDeletedEvent

[](#6-basketitemdeletedevent)

- **Object Included**: `$basketItem` (The removed basket item instance)
- **Usage**: This event can be used for actions similar to BasketItemUpdatedEvent, but specifically in response to item deletions.

Creating and Registering Custom Listeners
-----------------------------------------

[](#creating-and-registering-custom-listeners)

To create a custom listener for any of these events, generate a listener using the Artisan command:

```
php artisan make:listener YourCustomListener --event=BasketUpdatedEvent
```

In your custom listener, you can access the event object and its properties:

```
namespace App\Listeners;

use MrNewport\LaravelStow\Events\BasketUpdatedEvent;

class YourCustomListener
{
    public function handle(BasketUpdatedEvent $event)
    {
        $basket = $event->basket; // Access the updated basket
        // Implement your custom logic here
    }
}
```

Register your listener in the `EventServiceProvider`:

```
protected $listen = [
    'MrNewport\LaravelStow\Events\BasketUpdatedEvent' => [
        'App\Listeners\YourCustomListener',
    ],
];
```

Best Practices and Possible Pitfalls
------------------------------------

[](#best-practices-and-possible-pitfalls)

- Ensure correct instance configuration to prevent unintended item types.
- Utilize events for syncing basket states across the application.
- Monitor performance when using large baskets, and consider caching strategies.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance42

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

473d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/19dc283a8ecb45d1efbc444dc510eb63c8aab21427be09f3c1aefd507a5ab40c?d=identicon)[mrnewport](/maintainers/mrnewport)

---

Top Contributors

[![MrNewport](https://avatars.githubusercontent.com/u/48736345?v=4)](https://github.com/MrNewport "MrNewport (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mrnewport-laravel-stow/health.svg)

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

PHPackages © 2026

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