简体   繁体   English

Laravel表格ActionController表格

[英]Laravel Form ActionController form

Being new to Laravel, I do not quite understand how to add my input parameter in the form action controller as parameter. 作为Laravel的新手,我不太了解如何在表单动作控制器中将输入参数添加为参数。 I have a page which has an input field (id = mapsearch). 我有一个具有输入字段(id = mapsearch)的页面。

When I put some value in mapsearch and hit enter my url should change from /reviews to /reviews/{mapsearch} 当我在mapsearch中添加一些值并点击Enter时,我的网址应从/ reviews更改为/ reviews / {mapsearch}

I have the controller in place, however when I add the variable in form controller it does not work. 我有适当的控制器,但是当我在表单控制器中添加变量时,它不起作用。

Route::get('/reviews/{mapsearch}','SearchController@resendReviews'); 路线:: get('/ reviews / {mapsearch}','SearchController @ resendReviews');

And the code for opening the form. 以及用于打开表格的代码。

 {!! Form::open(array('action' => array('SearchController@postReviews', [$mapsearch]))) !!} 

Please let me know what should be the value of parameter when the id of my input field is $mapsearch. 当我输入字段的ID为$ mapsearch时,请让我知道parameter的值。

You can use whatever name you want in the parameter. 您可以在参数中使用所需的任何名称。 In the resendReviews method of the SearchController use the parameter as:- SearchControllerresendReviews方法中,将该参数用作:

function resendReviews($id)
{
    //The value of mapsearch will pass here.
    //U can name id whatever u want.
    echo $id;
}

Also if you are posting a form to a controller then you can access the posted data using.. 另外,如果要将表单过帐到控制器,则可以使用来访问过帐的数据。

function resendReviews($id)
{
    $input = Input::all();
    print_r($input);
}

But remember to use the following line when using Input.In the beginning a of Controller file add... 但是请记住在使用Input时使用以下行。在Controller文件的开头添加...

use Input;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM