Support the ongoing development of →
Configuration Requests Architecture
Last updated 2 years ago.
Route::get('/books/{id}/{name}', 'HomeController@showBook');

hey thanks for answering .. but this way the url in tha address bar will look like : which is not what I really want ....

I want to keep the same Route i defined with only the id as a parameter and show the name of the book in the address bar so it looks like :


Unfortunately you can't have your cake and eat it too. If you want to keep only the ID as a parameter, then it is not possible to include the title as a parameter.

You could probably make the ID look a little bit more obscure by using a route like '/books/{title}.{id}' which would give you a URL like but either way you will need both in there.


Ok I got it guys .. thanks for your answers even if I knew it before ;)


Not sure if its true, for example many websites have url like, without any integers or where is only date, but no post ids :)

Last updated 8 years ago.

Sure it's possible to have a string there but the string has to be something unique to identify the correct dataset. And you cannot call and then magically get id 15 there since that information has to come from somewhere. :)

With a middleware it might be possible.


As Ftiersch mentioned you need to have unique identify. Like Wordpress post name is convert to "slug" and stored in database with separate column with unique. You can do the same thing with laravel.

Laravel even have a helper function for it.

so, when you add the new book, you store book name and book slug. book slug needs to be unique. And your url should be like

Route::get('/books/{slug}', 'HomeController@showBook');

// in method

Book::where('slug', '=', $slug)->first(); 


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.