Ad
How To Resolve Urls Correctly In Laravel?
I have url for product details (domain.com/productdetail/1/name-of-product), When i click "about us" page while still in this url, I get an error "this url doesnt exist"(domain.com/productdetail/1/about-us). How can i get the url to resolve correctly to domain.com/about-us
This is my productDetail route
Route::get('/productDetail/{id}/{pro_name}',
'[email protected]');
this is about-us route
Route::get('about-us', function(){
return View('about');
});
I would like to get the exactly route (domain.com/about-us)
instead of it chaining at the end of the current url (domain.com/productdetail/1/about-us)
.
Ad
Answer
Better to put routes as named routes.
Route::get('/productDetail/{id}/{pro_name}','[email protected]')->name('product.view');
Route::get('about-us', function(){
return View('about');
})->name('about-us');
Call the specific route as
<a target="_blank" rel="nofollow noreferrer" href="{{route('about-us')}}">about us</a>
<a target="_blank" rel="nofollow noreferrer" href="{{route('product.view',['id' => $id, 'pro_name' => 'name_of_product'])}}">View Product</a>
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad