Hello
With '/{slug}-{id}' when you have this url : /my-product-343, slug = my and id = product and you have additionnal information so your route is wrong.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I work with laravel 5.3 and want to have slug and id in my url, like "/my-product-357/"... Only with slug it works, but if I add id then I get only 404!
My Route is: Route::get('/{slug}-{id}', ['uses' => 'ProductController@show'])->name('product.show');
My link to the resource is generated like: {{ route('product.show', ['slug' => $product->slug, 'id' => $product->id]) }}
This is ok. the url what I want is there like /my-product-343...
My Controller is: public function show($slug, $id) { $product = Product::SlugAndId($slug, $id)->firstOrFail(); return view('product.show', compact('product')); }
What I do wrong here?
You do not have to change your separator. Use regex instead
Route::get('/{slug}-{id}', function ($slug, $id) {
return [$slug, $id];
})->where('slug', '([0-9A-Za-z\-]+)')->where('id', '([0-9]+)');
Hope it helps
Please or to participate in this conversation.