App \ Http \ Controllers \ ProductsController :: edit()缺少参数1

时间:2017-02-22 08:25:08

标签: laravel

我正在编辑已保存的产品,我在浏览器上收到以下错误消息

  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'=>'ProductsController@edit'));

功能如下

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);
    }

我哪里错了

1 个答案:

答案 0 :(得分:0)

你应该提供路线ID

Route::get('productsedit/{id}', array('as'=> '/productsedit','uses'=>'ProductsController@edit'));

并且在你的函数中应该喜欢这个

`public function edit($id = null)
{
      //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);
}`

希望这项工作!!!

相关问题