2017-02-22 75 views
1

進出口工作在已保存的產品的編輯,我在我的瀏覽器收到以下錯誤消息缺少參數1爲App HTTP 控制器的ProductsController ::編輯()

ErrorException in ProductsController.php line 88: 
    Missing argument 1 for App\Http\Controllers\ProductsController::edit() 
    in ProductsController.php line 88 

我的路線控制器如下圖所示:

Route::get('productsedit', array('as'=> '/productsedit','uses'=>'[email protected]')); 

的功能如下

public function edit($id) 
    { 
      //find the post in the db and sav it as a variable 
     $product = Products:: findOrFail($id); 

     //return view and pass in the var previously created 
     return view('/productsedit')->withProducts($product); 
    } 

亞姆在哪裏我會錯

+0

更多信息請 –

+0

什麼是產品?嘗試使用view('/ productsedit',compact($ product)); – GuaHsu

+0

你能展示你如何鏈接到這條路線嗎? –

回答

2

在您的ProductsController您的編輯方法,你需要一個參數($id),但你沒有在你的路由值。這是什麼錯誤說的。

[缺少參數1 應用程序\ HTTP \控制器\的ProductsController ::編輯()]

您的路線:

Route::get('productsedit', array('as'=> '/productsedit','uses'=>'[email protected]')); 

將不得不改變,以這樣的:

Route::get('products/{$id}/edit', '[email protected]'); 

當調用視圖中的路線它將公頃已經到這個樣子:

'products/{{$product->id}}/edit' 

附加: 你可能想看看資源控制器,因爲你並沒有真正下列問題的REST慣例,當涉及到你的路由這個 https://laravel.com/docs/5.4/controllers#resource-controllers

相關問題