Route pattern cannot reference variable name more than once

更新日期: 2018-12-25 阅读次数: 5515 分类: Laravel

在用 Laravel Backpack 写一个定制化的 CRUD 页面。例如,一个指定店铺所拥有的商品的 CRUD 页面。

起初路由我是这样写的

CRUD::resource('products-of-store/{store_id}', 'ProductCrudController');

报错

Route pattern "/products-of-store/{store_id}/{{store_id}}" cannot reference variable name "store_id" more than once.

解决方法,Route 调整为

CRUD::resource('store/{store_id}/products', 'ProductCrudController');

即,Route 的最后设置为一个非变量。

出错的原因

我觉得是 resource 会自动将 route 最后的那个单词作为变量,所以出现了报错日志中的变量名重复的问题。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式