简体   繁体   English

在Laravel的URL中有破折号而不是下划线

[英]Have dashes rather than underscores in URL's in Laravel

I'd really like to be able to use Laravel (3) and have dashes as url separators rather than underscores. 我真的希望能够使用Laravel(3)并将破折号作为url分隔符而不是下划线。

I'd like to be able to do this automatically rather than having to define a new route for every_single_page too. 我希望能够自动执行此操作,而不必为every_single_page定义新路由。

I can't see how to achieve this, and make sure that Laravel works as normal at the same time. 我无法看到如何实现这一点,并确保Laravel同时正常工作。

Any help would be really gratefully received! 任何帮助都会非常感激!

Just use : 只需使用:

return Str::slug('My First Blog Post!');

It will echo a link like mypage/my-first-blog-post 它将回显像mypage / my-first-blog-post这样的链接

You can also be more precise : 你也可以更精确:

return Str::slug('My First Blog Post!', '_');

Will give mypage/my_first_blog_post 将给mypage / my_first_blog_post

您可以尝试使用.htaccess文件替换 - by _。

I've created pull request to the 3.x branch that fixes this issue. 我已经创建了解决此问题的3.x分支的pull请求

You can use both patch or my still-supported fork of 3.x branch of the framework. 您可以使用框架的3.x分支的补丁仍然支持的分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM