3

I need to pass an additional parameter($uid) from my index.blade.php to my edit.blade.php by clicking on a button.

My index.blade.php:

<a href="{!!action('FlyersController@edit', ['id' => Auth::user()->id, 'uid' => 1])!!}" type="button" class="btn btn-block btn-lg btn-info vorlageBtn card-link">Edit </a>

My FlyersController:

public function edit($id, $uid)
{

    return view('backend.flyers.edit')->withUid($uid);
}

With the code above I get an error: "Missing argument 2 for App\Http\Controllers\FlyersController::edit()"

What am I doing wrong here?

1
  • why don't you link a route instead? Commented Sep 27, 2016 at 12:24

4 Answers 4

2

The error is not throwing from the action method. It is coming from route for that URL.

Check the URL for passing argument to the the controller.

If this is the your desire URL localhost:8000/backend/flyers/10/edit?%24uid=1 then the second argument is in $request variable not in controller function argument.

Sign up to request clarification or add additional context in comments.

2 Comments

this is my route Route::resource('backend/flyers', 'FlyersController');
you are using resource routing the second argument is in query string so it is retrieve from the Request variable like $request->uid make sure to add Request variable in controller action
1

You should pass an array into action() helper:

action('FlyersController@edit', ['id' => Auth::user()->id, 'uid' => 1])

3 Comments

I also tried this. With the same result. By the way, this is the url I am redirected to after htitting the button "localhost:8000/backend/flyers/10/edit?%24uid=1". The uid is passed, but the FlyersController still makes trouble
Also with <a href="{!!action('FlyersController@edit', ['id' => Auth::user()->id, '$uid' => 1])!!}" type="button" class="btn btn-block btn-lg btn-info vorlageBtn card-link"> I still get an error witj missing argument 2
This does not work for me. Laravel 5.8
1

Ok, the only way I can solve this is by using the following in My FlyersController:

public function edit(Request $request, $id)
{

    return view('backend.flyers.edit')->withRequest($request);
}

and access then the uid with {{request->uid}} in my view.

If anybody has a better solution for this, let me know.

1 Comment

Not sure why you would need a better solution. This is a very good way to do it.
-1

Use this code

return view('backend.flyers.edit', ['var1' => $var1, 'var2' => $var2]);

That will pass two or more variables to your view

2 Comments

OP wants to pass parameters to a controller, not to a view.
Same result. The Controller still doesn't know about the param

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.