【发布时间】:2020-10-27 17:02:40
【问题描述】:
我正在制作一个电子商务网站,并尝试为普通用户/客户完成我的订单管理。如果状态仍处于待处理状态,我想允许客户取消订单。我有一个OrderHistoryController,内容如下:
public function cancel(Order $order)
{
$order->status = 'canceled';
$order->save();
//check if all suborders are canceled
$pendingSubOrders = $order->subOrders()->where('status','!=', 'canceled')->count();
if($pendingSubOrders == 0) {
$order->order()->update(['status'=>'canceled']);
}
return redirect('/order-history/{order}')->withMessage('Order was canceled');
}
我在 web.php 中创建了一条路线:
Route::get('/order-history/cancel', 'OrderHistoryController@cancel')->name('order-history.cancel')->middleware('auth');
我的刀片文件有一个按钮:
@if ($order->status == 'pending')
<button type="submit" class="default-btn floatright"><a href="{{route('order-history.cancel', $order)}}"> Cancel Order</a></button>
@endif
我想要做的是在单击按钮后将我的Order 表中的状态从“待处理”更新为“已取消”。当我这样做时,我在页面 localhost:8000/order-history/cancel 上被重定向
404|Not Found
似乎是什么问题?或者有没有其他方法可以做到这一点?任何建议将不胜感激。提前致谢!
【问题讨论】:
标签: laravel e-commerce crud