John
John

Reputation: 833

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.

I'd like to be able to do this automatically rather than having to define a new route for every_single_page too.

I can't see how to achieve this, and make sure that Laravel works as normal at the same time.

Any help would be really gratefully received!

Upvotes: 3

Views: 3638

Answers (3)

neoascetic
neoascetic

Reputation: 2546

I've created pull request to the 3.x branch that fixes this issue.

You can use both patch or my still-supported fork of 3.x branch of the framework.

Upvotes: 2

pimarc
pimarc

Reputation: 4145

Just use :

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

It will echo a link like 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

Upvotes: 4

JackPoint
JackPoint

Reputation: 4111

You can try replacing the - by _ with a .htaccess file.

Upvotes: 1

Related Questions