2017-09-26 17 views
0

我在web.php以下航线路由模式错误:无法引用变量名不止一次

Route::resource("api/companies/{kind}", "api\Companies", ['only' => ['index', 'create', 'store', 'show']]); 

有了这样的路线会给我一个错误:

Route pattern "/api/companies/{kind}/{{kind}}" cannot reference variable name "kind" more than once. 

但是,如果我从路径删除“显示”选项,它的工作原理:

Route::resource("api/companies/{kind}", "api\Companies", ['only' => ['index', 'create', 'store']]); 

看不到有什么不对我的路线,又有什么relationsh ip与'show'选项。

回答

0
Route pattern "/api/companies/{type}/{kind}" cannot reference variable name "kind" more than once. 

您不能在路由中使用两次变量。改变它别的东西。

+0

我不明白你的意思。我的路线上没有两次...? –

0

尝试删除您的通配符,

Route::resource("api/companies", "api\Companies", ['only' => ['index', 'create', 'store', 'show']]); 

请参阅本文档:https://laravel.com/docs/5.5/controllers#restful-partial-resource-routes

首页这个帮助:)

+0

我需要通过Laravel传递给我的控制器的{kind}。 –

+0

它使用资源路由时会自动给出通配符,为此,您可以在控制器中调用$公司。 – emjr

+0

不好意思,但不清楚你的意思。当使用资源路由时,你的意思是“拨打$公司” –

相关问题