masterix21 / laravel-cart
适用于任何Laravel项目的购物车功能
1.0.6
2021-06-07 10:56 UTC
Requires
- php: ^8.0
- cknow/laravel-money: ^6.1
- illuminate/contracts: ^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- livewire/livewire: ^2.4
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
README
这里应该放置您的描述。请将其限制在一到两段以内。考虑添加一个小示例。
安装
您可以通过composer安装此包
composer require masterix21/laravel-cart
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-migrations" php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Masterix21\LaravelCart\CartServiceProvider" --tag="laravel-cart-config"
用法
$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();
使用Blade视图
显示购物车项目计数器,该计数器会在购物车变化时自动刷新
<!-- 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" />
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志
贡献
有关详细信息,请参阅贡献指南
安全漏洞
请查看我们的安全策略以了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件