How to resolve urls correctly in Laravel?

how to get base url in laravel blade file
laravel get url parameters
laravel get current url
laravel redirect to url
laravel set base url
laravel url helper
laravel route
laravel request url

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}', 
'HomeController@detailPro');

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).


Better to put routes as named routes.

Route::get('/productDetail/{id}/{pro_name}','HomeController@detailPro')->name('product.view');

Route::get('about-us', function(){
  return View('about');
})->name('about-us');

Call the specific route as

 <a href="{{route('about-us')}}">about us</a>
 <a href="{{route('product.view',['id' => $id, 'pro_name' => 'name_of_product'])}}">View Product</a>

URL Generation - Laravel, For example, you may need to capture a user's ID from the URL. The given parameters will automatically be inserted into the URL in their correct positions: Sometimes you may wish to resolve Eloquent models using a column other than id  This is needed for Voyager to correctly resolve asset URLs. Set ADMIN_PASSWORD in your .env file if you want to specify an admin password. If not, the default password is 'password' php artisan ecommerce:install. This will migrate the database and run any seeders necessary. See this episode. npm install; npm run dev


Using alias as @jitheshJose has answered would fix your issue, but i think your issue is as simple as this:

You're on the page "domain.com/productdetail/1/name-of-product" and you have a link with href="about-us".

when this link is clicked, it will lead to "domain.com/productdetail/1/about-us".

to fix this, change the link in the href to href="/about-us".

To understand better what's happening here, lookup the difference between relative link and absolute link.

Routing - Laravel, So I guess it uses the local config correctly but only returns the host/domain. so can you tell me how you solve this problem in the end? Thx Add Column Action - Changing route() url yajra/laravel-datatables#1258. Closed. The resolve-url-loader@2.3.1 uses rework engine. So maybe also try resolve-url-loader@3.0.0 with engine:rework. That downgrades you from postcss back to rework but keeps the newly refactored/tested code. 🤔 I guess the sources look normal.


Here is an option you can use.

    Route::get('product-detail/{id}/{pro_name}', [
        'as' => 'product.view',
        'uses' => 'HomeController@detailPro',
    ]);

    Route::get('about-us', [
        'as' => 'about'
    ], function(){
          return View('about');
    });

Link:

 <a href="{{route('about')}}">About</a>
 <a href="{{route('product.view',['id' => $id, 'pro_name' => 'name_of_product'])}}">My Product</a>

Getting url() in a Command returns http://localhost · Issue #2554 , I've set up the Laravel 5 module, along with a few others. For some reason, the base url is not being constructed properly inside of the tests  6 Laravel 6 - My Route doesnt work in Resource Controller Sep 26 '19. 5 How to resolve urls correctly in Laravel?


Laravel 5 routes don't resolve correctly · Issue #2000 · Codeception , Not only that, but it will insert them in the correct order within the URI. Let's take a look at this in action. <?php // app/routes.php Route::get('the/{  Stack Exchange network consists of 177 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.


Laravel (5.7) URL Generation, To prevent this, old links should respond with a redirect to the correct url. Let's revisit our controller's detail method. This time, we'll need to pull in  Did you manage to resolve this? The fact that the admin panel is showing index.php in the example URL would seem to suggest that it has been unable to detect a suitable rewriting module (ie. mod_rewrite)? "the first option (plain permalinks) is without index.php and works fine" - Incidentally, that wouldn't need index.php anyway, even without mod_rewrite (providing the DirectoryIndex is set


Non-breaking, SEO friendly urls in Laravel, URLs Some frontend file paths are consistent but at times annoying to type—for has a single URL mapped to it, returns the correct URL given a controller and  I recently published a series of articles about creating a custom pagination view where users can enter the page number in a text box. On the second post I received a comment asking how to do pretty URLs with Laravel's paginator.