laravel 将参数从视图传递到路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28555655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel passing parameters from view to route
提问by dendic
Using a view with user input. I then want to pass to a route. This what I found so far: href="{{URL::to('customers/single'$params')}}"
使用带有用户输入的视图。然后我想传递到一条路线。这是我到目前为止发现的: href="{{URL::to('customers/single'$params')}}"
I want to pass the user input as the above $params to my route. This is sample of my route:
我想将用户输入作为上述 $params 传递给我的路线。这是我的路线示例:
Route::get('customer/{id}', function($id) {
$customer = Customer::find($id);
return View::make('customers/single')
->with('customer', $customer);
As soon as I can pass the parameter I can do what I want with the route, which I know how.
一旦我可以传递参数,我就可以对路线做我想做的事情,我知道如何做。
回答by Gaurav Dave
Basically you can pass parameter to routes by doing:
基本上,您可以通过执行以下操作将参数传递给路由:
Route::get('user/{name}', function($name)
{
//
})
->where('name', '[A-Za-z]+');
In your anchor tag, instead of doing href={{URL...}}, do something like:
在您的锚标记中,不要执行 href={{URL...}},而是执行以下操作:
{{ URL::to('user/$param') }}
For more information on routing, visit link
有关路由的更多信息,请访问链接
回答by dendic
This is what I have and works:
这就是我所拥有和工作的:
<a <button type="button" class="buttonSmall" id="customerView" href="{{URL::to('customer',array('id'=>'abf'))}}" >View</button></a>
But I need the array value 'abf' to be the value of a textbox.
但我需要数组值 'abf' 作为文本框的值。
回答by Seunope
This worked for me in my view anchor tag
这在我的视图锚标记中对我有用
href="{{ URL::to('user/'.$param) }}"
instead of what was specified above
而不是上面指定的
href="{{ URL::to('user/$param') }}"
回答by Sunil Rawat
You can user it in View as I used:
您可以像我使用的那样在 View 中使用它:
<a class="stocks_list" href="/profile/{{ Auth::user()->username }}">Profile</a>
Hope it helps you.
希望对你有帮助。