承接 mohammadv184/laravel-cart 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mohammadv184/laravel-cart

Composer 安装命令:

composer require mohammadv184/laravel-cart

包简介

A Cart for Laravel Framework

README 文档

README

Latest Stable Version Total Downloads Monthly Downloads Build Status License

A Shoping Cart for Laravel Framework

Installation

Install the package through Composer.

Run the Composer require command from the Terminal:

composer require mohammadv184/laravel-cart

If you're using Laravel 5.5, this is all there is to do.

Should you still be on version 5.4 of Laravel, the final steps for you are to add the service provider of the package and alias the package. To do this open your config/app.php file.

Add a new line to the providers array:

Mohammadv184\Cart\CartProvider::class

And optionally add a new line to the aliases array:

'Cart' => Mohammadv184\Cart\Facades\Cart::class,

Now you're ready to start using the laravel-cart in your application.

Database

To save cart into the database, the package needs to know which what the name of the table is. By default the package will use a table named cart_items. If you want to change these options, you'll have to publish the config file.

php artisan vendor:publish --provider="Mohammadv184\Cart\CartServiceProvider" --tag="config"

This will give you a cart.php config file in which you can make the changes.

To make your life easy, the package also includes a ready to use migration which you can publish by running:

php artisan vendor:publish --provider="Mohammadv184\Cart\CartServiceProvider" --tag="migrations"

This will place a cart_items table's migration file into database/migrations directory. Now all you have to do is run php artisan migrate to migrate your database.

Overview

Look at one of the following topics to learn more about Laravel-cart

Usage

The laravel-cart gives you the following methods to use:

Cart::put()

Adding an item to the cart is really simple, you just use the put() method, which accepts a variety of parameters.

In its most basic form you can specify the quantity, price and product model of the product you'd like to add to the cart.

$product=Product::find(1);
Cart::put([
    "price"=>10,
    "quantity"=>1
],$product);

Cart::update()

To update an item in the cart, you'll first need the rowId of the item. Next you can use the update() method to update it.

If you simply want to update the quantity, you'll pass the update method the product model or id and the new quantity:

$product=Product::find(1);
Cart::update(2,$product); // Will update the quantity

OR

$id = 'Biuwla5871';
Cart::update($id, 2); // Will update the quantity

If you want to update more attributes of the item, you can either pass the update method an array as the first parameter. This way you can update all information of the item with the given id.

Cart::update(['price' => 1000],"16cdac2cs8"); // Will update the price
$product=Product::find(1);
Cart::update(['id'=>"1c6a4c6a75",'price'=>1000], $product); // Will update the id and price

Cart::delete()

To delete an item for the cart, you'll again need the product model or id. This id you simply pass to the delete() method and it will delete the item from the cart.

$product=Product::find(1);
Cart::delete($product);

OR

$id = 'da39a3ee5e';
Cart::delete($id);

Cart::get()

If you want to get an item from the cart using its id or product model, you can simply call the get() method on the cart and pass it the id or product model.

$product = Product::find(1);
Cart::get($product);

OR

$id = 'da39a3ee5e';
Cart::get($id);

Cart::all()

Of course you also want to get the all items in cart. This is where you'll use the all method. This method will return a Collection of Cart Items.

Cart::all();

Cart::flush()

If you want to completely delete the all items of a cart, you can call the flush method on the cart. This will delete all Cart Items from the cart for the current cart instance.

Cart::flush();

Cart::totalPrice()

The totalPrice() method can be used to get the totalPrice of all items in the cart.

Cart::totalPrice();

Example

Below is a little example of how to list the cart content in a table:

// Add some items in your Controller.
$product=Product::find(1);
Cart::put(['quantity'=>1,'price'=>9.99],$product);
$product=Product::find(2);
Cart::put(['quantity'=>2,'price'=>10],$product);
// Display the content in a View.
<table>
   	<thead>
       	<tr>
           	<th>Product</th>
           	<th>quantity</th>
           	<th>Price</th>
        </tr>
   	</thead>
   	<tbody>
   		@foreach(Cart::all() as $row)
       		<tr>
           		<td>
               		<p><strong>{{$row->product->name}}</strong></p>
               	</td>
           		<td><p>{{$row->quantity}}</p></td>
           		<td>${{$row->price}}</td>
       		</tr>
	   	@endforeach
   	</tbody>
   	
   	<tfoot>
   		<tr>
   			<td colspan="2">&nbsp;</td>
   			<td>Total</td>
   			<td>{{Cart::totalPrice()}}</td>
   		</tr>
   	</tfoot>
</table>

mohammadv184/laravel-cart 适用场景与选型建议

mohammadv184/laravel-cart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cart」 「laravel」 「shopping cart」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mohammadv184/laravel-cart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mohammadv184/laravel-cart 我们能提供哪些服务?
定制开发 / 二次开发

基于 mohammadv184/laravel-cart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-03