laravelir/cart
Composer 安装命令:
composer require laravelir/cart
包简介
shop cart package
README 文档
README
cart package (In Develop)
a multi driver shopping cart package
Installation
- Run the command below to add this package:
composer require laravelir/cart
- Open your config/app.php and add the following to the providers/aliases array:
Laravelir\Cart\Providers\CartServiceProvider::class,
'Cart' => Laravelir\Cart\Facade\Cart::class,
- Run the command below to install package:
php artisan cart:install
Drivers
Session - Cookie - Eloquent - Cache
you can set your favorite driver in config file
eloquent driver need to authenticated user for save user's id
How to use
add HasCart trait to User model
this trait has one method:
$this->cart(); // return cart
Methods
$cart = resolve(Cart());
$cart->all();
$cart->add();
$cart->has();
$cart->update();
$cart->count();
$cart->delete();
$cart->truncate();
Helpers
cart(); cartItems();
Cart::user($user_id)->add(); Cart::driver('session')->add(); Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => ['size' => 'large']]);
Usage
$user = auth()->user();
$product = Product::first();
$cart = resolve(Cart());
$data = [ 'item' => $product, 'title' => $product->title, 'quantity' => 1, 'price' => $product->price, ];
$options = [ 'color' => 'red', 'size' => 'XL' ]; $user->cart->add($data, $options);
$data = [
]; Cart::update($itemId, $data); Cart::update($itemId)->increaseQuantity(); Cart::update($itemId)->decreaseQuantity(); Cart::all(); Cart::count(); Cart::get($itemId); Cart::delete($itemId); Cart::truncate();
Cartable Contract
For the convenience of faster adding items to cart and their automatic association, your model can implement Buyable interface. To do so, it must implement such functions:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Product exends Model implements Cartable { public function getCartableId() { return $this->id; } public function getCartableTitle() { return $this->title; } public function getCartablePrice() { return $this->price; } }
Events
The cart has following events:
cart.added - when an item added cart.updated - when an item cart updated cart.deleted - when an item deleted
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.
laravelir/cart 适用场景与选型建议
laravelir/cart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Laravel Support」 「lumen packages」 「laravel packages」 「lumen support」 「laravel-package」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravelir/cart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravelir/cart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravelir/cart 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Class to generate a standard structure for api json responses
a simple toolkit for social networks
ARCANEDEV Support Helpers
Amqp classes
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-02