ismail1k/laravel-cart
最新稳定版本:1.0.0
Composer 安装命令:
composer require ismail1k/laravel-cart
包简介
A simple Shopping Cart system for e-commerce projects for Laravel.
README 文档
README
A simple Shopping Cart system for e-commerce projects for Laravel.
Installation
First, add ismail1k/laravel-cart package to your laravel project using Composer:
composer require "ismail1k/laravel-cart"
then add these follow lines to config/app.php:
'providers' => [ Ismail1k\LaravelCart\ServiceProvider::class, ], 'aliases' => [ 'Cart' => Ismail1k\LaravelCart\CartServiceProvider::class, ],
Next step, add some published files like migrations:
php artisan vendor:publish --provider="Ismail1k\LaravelCart\ServiceProvider"
then run the follow line:
php artisan migrate
Usage
Use class Cart using:
use Cart;
Select your cart with:
$cart = Cart::get($cart_token);
Or you can create new one with:
$cart = Cart::create($user_id = null); //It by default null but if you want to link that created cart to a specified user, You can pass `user_id` parameter.
Add some product to your cart with:
Cart::add($cart_token, $product_id, $quantity = 1); //The default quantity is 1, that means if you don't specify the quantity, 1 will be added automatically.
Note: If you assign 2 to a product that already has 1 quantity, it will be 2, not 3.
Remove one item from cart with:
Cart::removeItem($product_id);
If you want to remove all products from the cart with a single action, you can do so with:
Cart:clear($cart_token);
Or you can destroy cart with:
Cart::destroy($cart_token);
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-26