https://github.com/matthewbdaly/laravel-cart
Simple shopping cart implementation for Laravel. Loosely inspired by CodeIgniter's shopping cart.
https://github.com/matthewbdaly/laravel-cart
cart laravel php shopping-cart
Last synced: 3 months ago
JSON representation
Simple shopping cart implementation for Laravel. Loosely inspired by CodeIgniter's shopping cart.
- Host: GitHub
- URL: https://github.com/matthewbdaly/laravel-cart
- Owner: matthewbdaly
- License: mit
- Created: 2017-11-15T11:31:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-13T22:30:32.000Z (over 6 years ago)
- Last Synced: 2024-04-14T04:02:28.506Z (about 1 year ago)
- Topics: cart, laravel, php, shopping-cart
- Language: PHP
- Homepage:
- Size: 37.1 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# laravel-cart
[](https://travis-ci.org/matthewbdaly/laravel-cart)
[](https://coveralls.io/github/matthewbdaly/laravel-cart?branch=master)Simple shopping cart implementation for Laravel. Loosely inspired by CodeIgniter's cart class.
Installation
------------```
composer require matthewbdaly/laravel-cart
```Usage
-----The cart implements the interface `Matthewbdaly\LaravelCart\Contracts\Services\Cart`, so you can use that to type-hint it. Alternatively you can use the `Cart` facade.
Add item
--------To add an item, call `$cart->insert($data)`. In this case `$data` must be an array with the following fields:
* `qty`
* `price`
* `name`
* `options`OR an array of items, each with the same fields. You can also add any additional data you wish.
Get all items
-------------Call `$cart->all()` to retrieve the contents.
Get single item
---------------Call `$cart->get($rowId)` to retrieve an item by its row ID.
Update single item
------------------Call `$cart->update($rowId, $data)` to update an item with the provided data.
Remove item
-----------Call `$cart->remove($rowId)` to remove an item.
Get total price
---------------Call `$cart->total()` to get the total price.
Get total items
---------------Call `$cart->totalItems()` to get a count of the items. Note that this does not allow for the quantity - if you have item X with a quantity of 2, that will be 1 item in the count.
Destroy cart
------------Call `$cart->destroy()` to destroy the cart.