Reputation: 85
I'm trying to call a controller method from a form object, to increment a given item.
The problem is that when adding the parameter, the form action will add a question mark, instead of a slash.
<form method="POST" action="http://localhost/admin/pages?1">
How am I to define the parameter?
{!! Form::open([
'action'=>['Admin\\PagesController@increment', $item->id],
'style' => 'display:inline'
]) !!}
{!! Form::submit('Move Up', ['class' => 'btn btn-danger btn-xs']) !!}
{!! Form::close() !!}
Upvotes: 3
Views: 7811
Reputation: 1
Your function shhould looks like this
public function increment($id)
{
//your code;
}
And your route should have id in it with post request
Route::post('increment/{id}','PagesController@increment');
Upvotes: 0
Reputation: 486
In you code sample, you are sending the item id as a HTTP GET parameter. You can access the item id in your controller by giving a name to the parameter as follows.
{!! Form::open([
'action'=>['Admin\\PagesController@increment','itemId='.$item->id],
'style' => 'display:inline'
]) !!}
Then access the item id in your controller by
Input:get('itemId')
Upvotes: 5