usually people will have slugs instead of name as they look more URL friendly..
you can do route model binding and then define the route binding key to be slug. all info is in documentation
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I can create posts via my controller. It works, but i like change id to {name}. I have a placeholder for Title, Body, Name.
Now i have http://localhost/posts/1,2...
Change to http://localhost/posts/name
My route is:
Route::resource('posts', 'PostsController');
My Controller@show:
public function show($id)
{
$post = Post::find($id);
return view('posts.show')->with('post', $post);
}
I migrate "name" in my db.
$table->string('name');
I try other answeres here in forum, but its not work.
Please or to participate in this conversation.