3

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() !!}
asked Jan 21, 2016 at 1:05
1
  • Did you try Admin\PagesController@increment? Commented Jan 21, 2016 at 1:57

2 Answers 2

5

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')
answered Jan 21, 2016 at 1:50
Sign up to request clarification or add additional context in comments.

3 Comments

Using the first option i get this error: Action App\Http\Controllers\/admin/pages/<?php echo e($item->id); ?> not defined Second options gives me an ErrorException: Array to string conversion
@Zalon it seems that you cannot pass parameters with post requests. So you need to choose the second method. I edited the code. Refer this answer: stackoverflow.com/questions/31872422/…
I played around with it a bit, I ended up getting it to work by using: 'url' => ['admin/pages/'.$item->id.'/increment'], instead of action. Thanks a lot for your help
0

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');
answered Jan 21, 2016 at 7:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.