laravelir/cart
最新稳定版本:0.1.0
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.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-02