Route parameters - no hyphen, only underscore

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!

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 58 courses (1056 lessons, total 44 h 09 min)
  • 78 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials