Download the PHP package centrex/laravel-cart without Composer
On this page you can find all versions of the php package centrex/laravel-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download centrex/laravel-cart
More information about centrex/laravel-cart
Files in centrex/laravel-cart
Package laravel-cart
Short Description Shopping cart for Laravel with session, cookie, and database storage, Livewire components, and REST API
License MIT
Homepage https://github.com/centrex/laravel-cart
Informations about the package laravel-cart
Laravel Cart
A full-featured shopping cart for Laravel. Supports session, cookie, and database storage drivers, multiple named cart instances (e.g. wishlist), Livewire components (CartIcon, CartDrawer), and a REST API — all swappable via a single config key.
Installation
For the database driver, run:
Configuration
Drivers
| Driver | Persists across requests | Auth-aware | Best for |
|---|---|---|---|
session |
Until session expires | No | Default, server-rendered apps |
cookie |
30 days (configurable) | No | Guest carts, headless/SPA |
database |
Permanently (until cleared) | Yes — uses user ID for auth, session ID for guests | Authenticated users, cart recovery |
Usage
Facade
Reading the cart
CartItem properties
Multiple cart instances
Use instance() to work with independent named carts. Returns a new Cart object — does not mutate the original singleton.
Events
Listen to cart events in your application's EventServiceProvider:
Cookie storage — guest carts
Note: Cookie writes are queued for the HTTP response. A
get()call in the same request reads what the browser already sent, not what was queued. This is standard browser behaviour.
Database storage — persistent & auth-aware
- Guests are identified by
session()->getId(). - Authenticated users are identified by
auth()->id(). - Cart rows are keyed on
(instance, identifier)— unique index.
To migrate a guest cart to a user after login:
Livewire Components
Requires livewire/livewire ^3.
CartIcon
Displays a shopping bag icon with an item count badge. Updates automatically when the cart changes.
Clicking the icon dispatches the open-cart browser event, which opens CartDrawer.
CartDrawer
A slide-out panel showing the full cart with quantity controls, item removal, and totals.
Open the drawer from any element:
Triggering a cart update from your own Livewire components
After adding an item to the cart in a Livewire component, dispatch cart-updated so CartIcon and CartDrawer refresh automatically:
Publish views for customisation
REST API
All endpoints are prefixed with api (configurable via api_prefix) and use the api middleware (configurable via api_middleware).
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/cart |
Get full cart (items, count, subtotal, tax, total) |
POST |
/api/cart/items |
Add item to cart |
PUT |
/api/cart/items/{rowId} |
Update item quantity |
DELETE |
/api/cart/items/{rowId} |
Remove item |
DELETE |
/api/cart |
Clear cart |
GET /api/cart
POST /api/cart/items
PUT /api/cart/items/{rowId}
DELETE /api/cart/items/{rowId}
Returns 204 No Content.
DELETE /api/cart
Returns 204 No Content.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- rochi88
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-cart with dependencies
illuminate/cookie Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0