Reputation: 543
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?
Upvotes: 3
Views: 3108
Reputation: 62
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.
Upvotes: 2
Reputation: 543
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.
Upvotes: 1
Reputation: 163948
You should pass an array into action()
helper:
action('FlyersController@edit', ['id' => Auth::user()->id, 'uid' => 1])
Upvotes: 1
Reputation: 1494
Use this code
return view('backend.flyers.edit', ['var1' => $var1, 'var2' => $var2]);
That will pass two or more variables to your view
Upvotes: -1