Download the PHP package sumonwd/laravel-cart without Composer
On this page you can find all versions of the php package sumonwd/laravel-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sumonwd/laravel-cart
More information about sumonwd/laravel-cart
Files in sumonwd/laravel-cart
Package laravel-cart
Short Description Session and database backed shopping cart and wishlist for Laravel, with multiple instances, vouchers, tax, shipping and guest-to-user merge on login.
License MIT
Homepage https://github.com/sumonwd/laravel-cart
Informations about the package laravel-cart
Laravel Cart
A shopping cart and wishlist for Laravel 11, 12 and 13.
- Multiple named cart instances (
default,wishlist,saved, ...) - Persistent storage: database, cache/redis, session or file
- Guest cart and wishlist merge into the user's cart on login
- Vouchers (percentage, fixed amount, max discount cap) through a pluggable resolver
- Tax and shipping totals
- Headless/mobile guest carts through an
X-Cart-Identifierheader CartUpdatedandWishlistUpdatedevents
Installation
The service provider and the Cart / Wishlist facades are auto-discovered.
Publish the config and, for the database driver, the migration:
Cart usage
Each item is an array:
Instances
Vouchers
By default codes come from config('cart.vouchers.codes'):
To validate codes from your database, implement VoucherResolverInterface:
Then set 'vouchers.resolver' => App\Cart\DatabaseVoucherResolver::class in config/cart.php.
Wishlist usage
The wishlist looks up the product's name, price, slug and image through a product resolver. Point it at your model:
For anything more complex, implement Sumonwd\Cart\Contracts\ProductResolverInterface and set wishlist.product_resolver.
Guest carts and login merge
- Logged-in users (web or Sanctum) are stored as
user_{id}. - Web guests get a random id kept in the session.
- API clients can send an
X-Cart-Identifierheader to keep a guest cart.
When Illuminate\Auth\Events\Login fires, the guest's cart and wishlist are merged into the user's stored cart. Quantities of matching rows are added together, and guest vouchers are kept. Turn this off with 'merge_on_login' => false.
Events
| Event | Properties |
|---|---|
Sumonwd\Cart\Events\CartUpdated |
items, instance, identifier |
Sumonwd\Cart\Events\WishlistUpdated |
items, instance, identifier |
Customising
Every part is bound to an interface, so you can swap it in your AppServiceProvider:
| Interface | Default |
|---|---|
CartStorageInterface |
CartStorageService |
CartCalculatorInterface |
CartCalculator |
SessionManagerInterface |
CartSessionManager |
VoucherResolverInterface |
ConfigVoucherResolver |
ProductResolverInterface |
ModelProductResolver |
Messages can be translated after php artisan vendor:publish --tag=cart-lang.
Laravel Octane
The cart services are singletons that remember the current user. Flush them on every request in config/octane.php:
Testing
License
MIT. See LICENSE.md.
All versions of laravel-cart with dependencies
illuminate/auth Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/events Version ^11.0|^12.0|^13.0
illuminate/session Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0