Archie Rombo
Archie Rombo

Reputation: 43

Missing argument 1 for App\Http\Controllers\ProductsController::edit()

Im working on editing of an already saved product and i am getting the following error message on my browser

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

My route controller is as below:

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

The function is as below

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

Where iam i going wrong

Upvotes: 1

Views: 6453

Answers (2)

Datha Reico
Datha Reico

Reputation: 9

your should give route id

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

and in your function should like this

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

hope this work !!!

Upvotes: 0

Christophvh
Christophvh

Reputation: 13254

In your edit method on your ProductsController you require a parameter ($id), but you don't have that value in your route . Which is what this error is saying.

[Missing argument 1 for App\Http\Controllers\ProductsController::edit()]

Your route:

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

Will have to change to something like this:

Route::get('products/{$id}/edit', 'ProductsController@edit');

When calling the route in your view it will have to look something like this:

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

Extra: You might want to take a look at Resource controllers since you are not really following restfull practices when it comes to your routes https://laravel.com/docs/5.4/controllers#resource-controllers

Upvotes: 2

Related Questions