dongmu1390 2014-10-12 02:40 采纳率: 100%
浏览 25
已采纳

Laravel路由问题

I am using laravel framework. I've setup couple of routes that take a parameter like example.com/route/{dir_name}. When I pass in a dir which has childrens it considers it as another route. Is there a way to bypass it?

I'm using this code:

Route::get('/route/something/{path}',array('as'=>'something',function($path){
     return $path;
}));

When I use /route/something/home/user/dev it throws a Symfony\Component\HttpKernel\ Exception\NotFoundHttpException exception.

  • 写回答

2条回答 默认 最新

  • dravpuso44681 2014-10-12 04:40
    关注

    You can try using constraints on the route parameter with a regular expression.

    Route::any('/route/{dir_name}', function ($dir_name) {
        return $dir_name;
    })->where('dir_name', '.*');
    

    See the docs section about route parameters, specifically the "Regular Expression Route Constraints" part.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部