Skip to main content
Tutorial Free

Route parameters - no hyphen, only underscore

July 07, 2016
1 min read
Lately I've been re-reading full Laravel documentation and found quite a lot of "small details" which no one actually noticed in tutorials or books. One of these is using "-" symbol in route parameters. Let me show you what I mean: This is correct way of using parameter:
Route::get('posts/{post}', function ($postId) {
    //
});
This is incorrect way of using parameter:
Route::get('posts/{post-id}', function ($postId) {
    //
});
Apparently, you cannot use "-" in parameter, like post-id here. Instead, you can use underscore, like this:
Route::get('posts/{post_id}', function ($postId) {
    //
});
Probably you're wondering why I'm telling you this? It's such a small detail! The thing is if you do use "-" symbol, you won't receive any visible error, that route just won't work and you will probably receive 404 page. And you will be wondering what the hell is wrong in this world. And yes, it's mentioned in the official documentation. Hope that helps!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.