在laravel中使用资源控制器时,变量未传递到视图

时间:2019-02-18 06:51:52

标签: laravel

我的应用程序中有一条资源路由Route::resource('orders', 'BackendController');。在路由列表中,其orders/{order}/edit路由用于编辑顺序,orders/{order}用于更新顺序。在edit-order.blade.php中具有<form>标签。在表单标签内,我已经定义了action="{{route('orders.update',$order->id)}}" method="post"并放了@csrf & @method('PUT')。在我的BackendController中,我已经编辑和更新了功能,如下所示->

public function edit(Order $order){
   return view('backEnd.edit-order', compact('order'));
}

public function update(Request $request, Order $order){
    $order->address             = $request->address;
    $order->city                = $request->city;
    $order->state               = $request->state;
    $order->appointment         = $request->appointment;
    $order->client              = $request->client;
    $order->special_instruction = $request->special_instruction;
    $order->first_name          = $request->first_name;
    $order->last_name           = $request->last_name;
    $order->mobile_phone        = $request->mobile_phone;
    $order->home_phone          = $request->home_phone;
    $order->email               = $request->email;
    $order->save();
    return redirect()->back();
}

似乎我正在将路由所需的$order变量传递给edit-order.blade.php,但是我遇到了错误-> undefined variable order。这是怎么了?以及如何解决这个问题?

0 个答案:

没有答案