Laravel 5.2带有可变参数的命名路由用法 [英] Laravel 5.2 named route usage with variable parameter

查看:194
本文介绍了Laravel 5.2带有可变参数的命名路由用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条这样的路线:

// 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.

如何在仍使用命名路由的情况下为变量菜单传递一个值(而不是在href中硬编码url)?

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

推荐答案

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

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

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

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

Make sure you're using correct names. Your routing defines subscription.create route while your template refers to organisations.index route.

这篇关于Laravel 5.2带有可变参数的命名路由用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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