php - 产品正在更新而不是新产品插入 laravel?
问题描述
麻烦你看看我的问题...
我设计了三类产品
- Sp 2. Hp 3. Gp
三个类似图像的菜单(包括在内)。
我已经完成了我的代码......
<table class="table table-bordered">
<!-- Table Header -->
<thead>
<tr>
<th>#</th>
<th>Image</th>
<th>Product Name</th>
<th>Net Weight</th>
<th>Category</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@php
$all_product = DB::table('products')
->join('categories', 'products.cat_id', '=', 'categories.id')
->where('cat_name', 'SP Products')
->get();
@endphp
@foreach($all_product as $row)
<tr>
<form action="{{ url('/add-to-cart') }}" method="POST">
@csrf
<input type="hidden" name="product_id" value="{{ $row->id }}">
<input type="hidden" name="product_name" value="{{ $row->product_name }}">
<input type="hidden" name="product_qty" value="1">
<input type="hidden" name="product_price" value="{{ $row->selling_price }}">
<input type="hidden" name="product_weight" value="{{ $row->net_weight }}">
<input type="hidden" name="product_image" value="{{ $row->product_image }}">
<td>{{ $row->product_serial }}</td>
<!-- Product image -->
<td>
<a href="#">
<img src="{{ $row->product_image }}" alt="" class="img-responsive" style="width: 30px; height: 30px;" />
</a>
</td>
<td><a href="#"> {{ $row->product_name }} </a></td>
<td>{{ $row->net_weight }}</td>
<td>{{ $row->cat_name }}</td>
<td>{{ $row->selling_price }}</td>
<td><button type="submit" class="btn btn-warning btn-sm"> Add to Cart</button></td>
</form>
</tr>
@endforeach
</tbody>
</table>
在 web.php 中
Route::post('/add-to-cart', 'front\AddtoCartController@add_to_cart')->name('add_to_cart');
AddtoCartController.php
public function add_to_cart(Request $request)
{
$qty = $request->product_qty;
$product_id = $request->product_id;
$product_info=DB::table('products')->where('id', $product_id)->first();
$data['qty']=$qty;
$data['id']=$product_info->id;
$data['name']=$product_info->product_name;
$data['price']=$product_info->selling_price;
$data['weight']=0;
$data['options']['image']=$product_info->product_image;
Cart::add($data);
return Redirect::to('show-cart');
}
当我将产品添加到购物车时,正确的产品没有添加到购物车,添加另一个产品并增加另一个产品数量。
请帮忙。谢谢
解决方案
推荐阅读
- swift - 向现有项目添加共享扩展。所以已经存在的项目 pod 开始出现错误
- python - 如何将字体标签设置为 Helvetica 并使用 matplotlib 重新设计轴标签文本
- openshift - VMware 上的 Openshift OKD 4.5
- javascript - 将数组数组附加到 FormData 并通过 AJAX 发送
- angular - 我们如何覆盖 angular2-query-builder 中的 getInputType 函数
- hive - 为什么 Hive 不应该在其操作中使用 TRUNCATE?
- react-native - 从redux获取后如何保存数据?
- c# - 获取根目录剃须刀页面
- javascript - 更新打字稿版本时反应useState钩子上的打字稿错误
- html - 正文、HTML 尺寸过大