【问题标题】:Laravel - Named Route + Controller Routing + Parameter Validator not working togetherLaravel - 命名路由 + 控制器路由 + 参数验证器不能一起工作
【发布时间】:2014-11-07 15:20:18
【问题描述】:

我有一个使用完美运行的控制器的命名路由。当我链接参数验证器时出现问题,以确保传递的问题 id 是数字。

Route::get('/question/{id}',
array('as' => 'question_route', 'uses' => 'QuestionsController@showQuestion'))
->where('id',[0-9+]);

Laravel 抛出这个异常,突出显示 ->where('id',[0-9+]);

Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected ']'

所有 3 个(as、uses、where)如何在一条路线上协同工作?

【问题讨论】:

    标签: laravel laravel-routing


    【解决方案1】:

    你确定正则表达式是[0-9+] 不是[0-9]+

    而且应该用单引号括起来

    【讨论】:

    • 这是我的愚蠢错误,感谢艾伦指出。我还想补充一点,它也应该用单引号括起来 - 我会更新你的答案:)
    猜你喜欢
    • 2020-02-08
    • 2021-09-06
    • 1970-01-01
    • 2015-07-20
    • 2015-06-10
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    相关资源
    最近更新 更多