Laravel post route with url parameters

我们两清 提交于 2019-12-04 04:10:56

The problem has nothing to do with Laravel

<form url="/request/{{$equipment->url}}" method="POST">

replace url with action

<form action="/request/{{$equipment->url}}" method="POST">

The HTTP POST verb doesn't accept parameters from the URL like GET, it accepts them from the Body of the HTTP POST. To fetch the post parameters you use the code below:

In routes.php:

Route::post('/request', 'PagesController@request');

and in your PagesController access the form input using one of the input methods such as below

public function request() 
{
    return Input::get('equipment_url');
}

You can not send get parameters to post route.

But you can achieve that by a simple trick, just pass your value ({{$equipment->url}}) in form's hidden filed or in session.

For Example:

html

<form url="test/{{$equipment->url}}" method="POST">
    {{Input::hidden('name-of-field', $equipment->url)
    <div class="row">
        .......
    </div>
</form>

route

Route::post('test/{any-variable}', ['as' => 'test', 'uses' => 'TestController@test']);

controller

public function test()
{
    echo "<pre>";
    dd(Input::all());
}

result

array(1) {
           ["name-of-field"]=>
            string(5) "your value here"
          }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!