Search code examples
laravellaravel-form

Laravel passing 2 parameters for update method


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

Solution

  • 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!