I have following routes in my routes/web.php.
Route::get('page/{slug}', 'PageController@index')->name('front.page.slug');
Route::get('inquiry/contact-us', 'ComplaintController@index')->name('front.complaint');
Route::get("product/{product}", 'ProductController@show')->name('front.get.product');
Its working e.g.
- https://example.com/page/about-us
- https://example.com/page/terms-&-condition
- https://example.com/page/privacy-policy
- https://example.com/inquiry/contact-us
- https://example.com/product/product-slug-any
when i change my routes it showing me error that product doesn’t exit in page model.
Route::get('{slug}', 'PageController@index')->name('front.page.slug');
Route::get('contact-us', 'ComplaintController@index')->name('front.complaint');
Route::get("{product}", 'ProductController@show')->name('front.get.product');
i have no idea how to start routes with slugs without resource name for SEO friendly URLs E.g.
3
Answers
If you do like that. contact-us page execute in front.page.slug route.
You can not use two variable in route file.
Make like this:
and determine {slug} ‘s category in controller. Is page or is product? Do this in same controller. Otherwise just first {} works in route file.
laravel does not consider {slug} and {product} as two different routes
you can do it like this example:
you should consider a diffrence between two route.
{product} and {slug} are the same