masterix21/laravel-cart
Composer 安装命令:
composer require masterix21/laravel-cart
包简介
Cart features for any Laravel Project
关键字:
README 文档
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require masterix21/laravel-cart
You can publish and run the migrations with:
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-config"
Usage
$product = YourProductModel::first(); // // Add a product to cart $cartItem = Cart::add(label: $product->name, item: $product, price: $product->price, quantity: 1); // // Change the cart item quantity Cart::set($cartItem, 2); // or $cartItem->setQuantity(2); // // Increase the cart item quantity Cart::increase($cartItem); // to increase of 1 Cart::increase($cartItem, 5); // to increase of 5 $cartItem->increase(); // to increase of 1 $cartItem->increase(5); // to increase of 5 // // Decrease the cart item quantity, and if the // quantity is zero, removes the item from the cart. Cart::decrease($cartItem); // to decrease of 1 Cart::decrease($cartItem, 5); // to decrease of 5 $cartItem->decrease(); // to decrease of 1 $cartItem->decrease(5); // to decrease of 5 // Retrieve all cart items $items = Cart::items(); // Clear the cart Cart::clear();
Views using Blade
Display the cart items counter that will auto-refresh on cart changes:
<!-- Automatic refresh the counter --> <livewire:cart-counter /> <!-- Force the displayed value --> <livewire:cart-counter :count="10" no-auto-refresh /> <!-- Customize the component using class argument like so --> <livewire:cart-counter class="text-xs text-white rounded-full bg-red-700" /> <!-- Improve the result by its state --> <livewire:cart-counter class="text-xs rounded-full" empty-class="bg-gray-100 text-gray-500" not-empty-class="bg-red-700 text-white" />
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-14