Reputation: 496
I know I am doing something very basic here but I can't seem to find the issue. My form isn't routing to its named route.
Am I naming my route
the wrong way?
Form
<form action="{{route('inventory.deduct', 'test')}}" method="post">
@csrf
<div class="modal-body">
Enter number of items to issue for:
<input type="text" name="itemname" id="itemname" class="form-control" readonly>
<input type="text" id="itemid" name="itemid" hidden>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</form>
Route
Route::post('inventory/{id}/deduct', 'InventoryController@deduct')->name('inventory.deduct');
Upvotes: 3
Views: 70
Reputation: 21
<form action="{{route('inventory.deduct', $itemid)}}" method="post">
Upvotes: 1
Reputation: 1814
Change your route parameter as follows..
<form action="{{route('inventory.deduct', ['id'=>$itemid])}}" method="post">
OR
<form action="{{route('inventory.deduct', $itemid)}}" method="post">
Both will work..
Upvotes: 1
Reputation: 15296
Pass {id}
in an array as you called in web.php file. ['id'=>$itemid] add it in your route of form because in web.php file you're expecting id so you need to pass it in form.
<form action="{{ route('inventory.deduct',['id'=>$itemid]) }}" method="post">
@csrf
</form>
web.php is correct.
Route::post('inventory/{id}/deduct', 'InventoryController@deduct')
->name('inventory.deduct');
Upvotes: 0
Reputation: 133
You change your action route because you pass the parameter in route.
FORM
<form action="{{route('inventory.deduct',$collection->id)}}" method="post">
@csrf
<div class="modal-body">
Enter number of items to issue for:
<input type="text" name="itemname" id="itemname" class="form-control" readonly>
<input type="text" id="itemid" name="itemid" hidden>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</form>
Route
Route::post('inventory/{id}/deduct', 'InventoryController@deduct')
->name('inventory.deduct');
I hope this i may help you.
Upvotes: 0