Laravel passing 2 parameters for update method

3.9k Views Asked by At

I have an EDIT button

<td><a href="{{action('InventoryItemController@edit', [$inventoryitem['id'], $inventoryitem['inventory_id']])}}" class="btn btn-warning">Edit</a></td>

And when i press it, it should edit an item based on ID and then when i update it, it should update it based on ID which works, but when I want to redirect back to index page I have to pass argument for that index method. So i added that inventory_id parameter to be passed along ID parameter but it wont recognize my inventory_id parameter in mine form.

<form method="put" action="{{action('InventoryItemController@update', $id, $inventory_id)}}">

But i get this error

Undefined variable: inventory_id 

my route is like this

Route::post('inventory-items/{id}/{inventory_id}', 'InventoryItemController@update');
2

There are 2 best solutions below

1
On BEST ANSWER

Error is here:

<form method="put" action="{{action('InventoryItemController@update', $id, $inventory_id)}}">

The route should look like:

route('InventoryItemController@update', ['id' => $id, 'inventory_id' => $inventory_id ])

Good luck!

0
On

I found easier way to do it, I just used one of the parameters ($id) in controller to find second parameter. Thanks for answers.