【发布时间】:2018-06-19 09:10:16
【问题描述】:
我有orders 表,其中有名为cart 的列,并且该列中的数据是从我的购物车中序列化的。
现在我尝试为管理员创建订单编辑功能,他们可以在其中编辑订单,到目前为止我可以从我的序列化数据中获取我的数据,例如quantity。
我的问题是如何在我的cart 列中编辑该数据(在本例中为quantity),而不会弄乱其中的其余数据?
这是我的更新功能(仍然与数量无关):
public function update(Request $request, $id)
{
$order = Order::find($id);
$this->validate($request, array(
'payment_id'=>'nullable',
'orderstatus_id' => 'required|numeric',
'address_id' => 'required|numeric',
));
$order = Order::where('id',$id)->first();
$order->payment_id = $request->input('payment_id');
$order->orderstatus_id = $request->input('orderstatus_id');
$order->address_id = $request->input('address_id');
$order->save();
return redirect()->route('orders.index',
$order->id)->with('success',
'Order updated successfully.');
}
这是我在order.edit 页面中显示订单数量的方式:
function
public function edit($id)
{
$order = Order::find($id);
$order->cart = unserialize($order->cart);
$statuses = Orderstatus::all();
$addresses = Address::where('user_id', $order->user_id)->get();
return view('admin.orders.edit', compact('order', 'statuses', 'addresses'));
}
blade
<div class="row mt-20">
@foreach($order->cart as $item)
<div class="col-md-4">
{{ Form::label('quantity', 'Quantity') }}
{{ Form::text('quantity', $item['quantity'], array('class' => 'form-control')) }}
</div><!--end col-md-4-->
@endforeach
</div><!--end row-->
谢谢。
更新
我的序列化代码示例
O:32:"Darryldecode\Cart\CartCollection":1:{s:8:"�*�items";a:1:{i:29;O:32:"Darryldecode\Cart\ItemCollection":2:{s:9:"�*�config";a:4:{s:14:"format_numbers";b:0;s:8:"decimals";i:0;s:9:"dec_point";s:1:".";s:13:"thousands_sep";s:1:",";}s:8:"�*�items";a:6:{s:2:"id";i:29;s:4:"name";s:6:"effewf";s:5:"price";d:24524;s:8:"quantity";i:3;s:10:"attributes";O:41:"Darryldecode\Cart\ItemAttributeCollection":1:{s:8:"�*�items";a:0:{}}s:10:"conditions";a:0:{}}}}}
【问题讨论】:
标签: php laravel serialization