Php 产品正在更新,而不是新产品插入laravel?
请你看看我的问题 我设计了三类产品Php 产品正在更新,而不是新产品插入laravel?,php,laravel,cart,Php,Laravel,Cart,请你看看我的问题 我设计了三类产品 Sp 2。惠普3。全科医生 三个菜单式图像(包括) 我已经做了我的代码像 <table class="table table-bordered"> <!-- Table Header --> <thead> <tr> <th>#</th> <th>Image</th> <th>Product Name</th> <
<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>
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');
}
当我将一个产品添加到购物车时,正确的产品并没有添加到购物车,添加另一个产品并增加另一个产品数量
请帮忙。
谢谢
购物车::添加($data)
我不知道add方法,你在哪里找到的?你可以使用这个购物车::where('id',$data['id')->update([$data])
您必须显示什么是购物车
,因为它看起来不像一个模型,我们不知道添加
在做什么?
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');
}