Add provider to config/app.php file.
'providers' => [
...
\Baboot\CartServiceProvider::class
];Add alias to config/app.php file.
'aliases' => [
...
'Cart' => \Baboot\Facades\Cart::class
];Publishing config
php artisan vendor:publishImport migrations
php artisan migrateSpecify model that beign used for adding to cart. For that, in model class insert trait and specify attributes. For example:
<?php
class Product extends Illuminate\Database\Eloquent\Model
{
use App\Package\src\Mixins\Cartable;
protected $cart_price_arrtibute = 'price';
protected $cart_item_id = 'id';
...
}In this case Cart will used price attribute for price and id from attribute id. If price is aggregatable attribute you may specify an accessor of price attribute
First thing you need to do is init the cart:
\Cart::init($key)where $key is a key for a cart for current user. You need to specify them dependings on your application rules. $key is a primary key varchar(12)
Adding item to cart
\Cart::add($model)Removing item to cart
\Cart::remove($model)Count of all items in cart
\Cart::totalQuantity()get total in cart without price modifacators(coupons)
\Cart::subTotal()get total in cart with price modifacators(coupons)
\Cart::total()set quantity for a product
\Cart::setQuantity($model, $quantity)cart.inited
cart.action.added
cart.action.removed
cart.action.flush
cart.action.coupon.added
You can store cart in DB ot Redis. Specify CART_STORAGE var in your .env file, or change it config (cart.php) Also you can create your own driver(implementing Baboot\Contracts\Storage ) and add it in storageDrivers directive in config and use them.