在Laravel 5的路线中使用表单参数 [英] Use form parameters in a route with Laravel 5

查看:59
本文介绍了在Laravel 5的路线中使用表单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下我的route.php文件中包含以下内容:

Imagine I have the following in my routes.php file:

Route::get('/test/{system}/{link}', function($system,$link)
{
    return "test ok";
});

然后,我想从我的视图中以表格的形式访问此路线:

Then, I wanna access this route with a form from my view:

<form action="/" method="get">
    <input type="text" name="system">
    <input type="text" name="link">
    <button type="submit">Go!</button>
<form>

做到这一点的最佳方法是什么?我知道我可以做类似的事情:

What would be the best way to do that? I know I can do something like:

Route::get('/',function(){
    $input = Request::only('link','system');
    $url = 'test/'.$input['system'].'/'.$input['link'];
    return redirect($url);
});

但是我不确定这是否是实现它的正确方法.

But I'm not sure if it's the correct way to achieve it.

提前谢谢!

推荐答案

您可以让js更改表单操作,然后提交.可以,但请确保将其放在路由文件的末尾.实际上,我会将表单提交到某些特定的路由(而不是/也许是/redirect-to之类的东西),然后从那里重定向.

You could have js change the form action and then submit it. Your way is ok, but make sure to put it at the end of the routes file. I would actually have the form submit to some specific route (instead of / maybe /redirect-to or something) and from there redirect.

这篇关于在Laravel 5的路线中使用表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆