Laravel 5.2 命名路由使用可变参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34556484/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:56:41  来源:igfitidea点击:

Laravel 5.2 named route usage with variable parameter

phplaravelrouteslaravel-5laravel-5.2

提问by TheRealPapa

I have a route like this:

我有一条这样的路线:

// Open New Subscription page
Route::get('/account/subscriptions/create/{menu}', ['uses' => 'Subscriptions\SubscriptionController@create', 'as' => 'subscription.create']);

In my blade template I use the named route like this:

在我的刀片模板中,我使用这样的命名路由:

<a href="{!! route('organisations.index') . "/p11-c3" !!}">

But this format does not work.

但是这种格式不起作用。

How do I pass the variable menu a value while still using the named route (rather than hard coding a urlin the href)?

如何传递变量菜单中的值,而仍使用已命名的路线(而不是硬编码urlhref)?

回答by jedrzej.kurylo

You can pass your route parameters as the second argument to route()helper:

您可以将路由参数作为第二个参数传递给route()助手:

<a href="{!! route('organisations.index', ['menu' => 'p11-c3']) !!}">

Make sure you're using correct names. Your routing defines subscription.createroute while your template refers to organisations.indexroute.

确保您使用正确的名称。您的路由定义了subscription.create路由,而您的模板引用了organizations.index路由。