Good day All I'm am working on my first laravel project and I ran into a problem that I cant seem to fix. I have a few basic views, controllers, and routes that work together with a basic HTML navbar. The problem I am having is that when I click on the next page in my navbar it works fine and it goes to the link but when clicking on another link from that page it adds to the path and then it can't find the page. My routes work through the basic controllers that return a view only for now For example
Example:
Home page=http://127.0.0.1:8000/
Click on Movies=http://127.0.0.1:8000/movie/index
Click on Movie Actor=http://127.0.0.1:8000/movie/actor/index
from movies to the next view it does not work as you can see the link path is wrong it should be http://127.0.0.1:8000/actor/index
please if anyone has any suggestion that might help.
CodePudding user response:
Please edit your questions with the code and include the relevant code for the future. The code you posted doesn't contain any links (Edit: in your first few comments), which gives me a reason to believe you pasted the wrong thing.
The problem (without seeing any of your code) is likely here.
<a href="movie/index".....</a>
The way this (a) element works, which has nothing to do with Laravel, but is purely HTML, is that it will add movie/index
to the current path you are linking from because you are giving it a "relative" URL.
If you add this link from, e.g. yoursite.com
- it will link to yoursite.com/movie/index
if you do it from yoursite.com/dashboard
, it will link to yoursite.com/dashboard/movie/index
.
Instead, you do not want a relative path, so you need to start with a /
like this.
<a href="/movie/index".....</a>
You can read more about HTML tags here: https://www.w3schools.com/tags/att_a_href.asp.
CodePudding user response:
Check named routes in documentation.
Route::get('/user/profile', function () {
//
})->name('profile');
You can get absolute url in blade template with route helper.
<a href="{{ route('profile') }}">Text</a>