【问题标题】:Route pattern error: cannot reference variable name more than once路由模式错误:不能多次引用变量名
【发布时间】:2017-09-26 01:26:00
【问题描述】:

我在 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']] );

看不到我的路线有什么问题,与“显示”选项有什么关系。

【问题讨论】:

    标签: laravel laravel-5.3


    【解决方案1】:

    尝试删除您的通配符,

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

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

    主页这个帮助:)

    【讨论】:

    • 我需要 Laravel 传递给我的控制器的 {kind}。
    • 它在使用资源路由时自动给出一个通配符,你可以在你的控制器中调用$companies。
    • 对不起,但不清楚你的意思。 “打电话给$companies”是什么意思
    • 在使用资源路由的时候,会自动给一个通配符,也就是不需要给通配符{kind},如果要使用通配符{kind}可以使用,Route::resource ("api/companies/kind", "api\Companies")..
    【解决方案2】:
    Route pattern "/api/companies/{type}/{kind}" cannot reference variable name "kind" more than once.
    

    您不能在路由中使用该变量两次。换个别的吧。

    【讨论】:

    • 我不明白你的意思。我的路线中没有两次...?
    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多