Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Norbertho's avatar

Laravel resource route

Hi, I have a gallery and when i visit one of my gallery album my URL in a browser looks "http://127.0.0.1:8000/showalbum/15" like this. Then from there i want to visit my admin page and i click my admin link then it takes me to the wrong place URL: "http://127.0.0.1:8000/showalbum/admin" but it should be "http://127.0.0.1:8000/admin". If i am on my home page and i click my admin link then it takes me to the right place. I am using resource routing. web.php

Route::resource('admin', 'AdminController');
Route::get('/showalbum/{id}', 'GalleryController@showalbum')->name('showalbum');

and my link to the admin page

<a href="{{route('admin.index')}}" class="block px-4 py-2 hover:bg-gray-200">Admin Page</a>
0 likes
5 replies
ollie_123's avatar

Hey @norbertho

instead of using

<a href="{{route('admin.index')}}" class="block px-4 py-2 hover:bg-gray-200">Admin Page</a>

why not try

<a href="/admin" class="block px-4 py-2 hover:bg-gray-200">Admin Page</a>

That will then call the route and in turn open the view page of Admin.

Let me know how you get on.

Oussama.tn's avatar

Show us your route list:

php artisan route:list

It's not a good idea to usehref="/admin". Imagine, someday, you want to change the url to "/secret-admin".. the you have to change it in all your code. By using named route, you just change it inside your routes/web.php

1 like
snake03's avatar
snake03
Best Answer
Level 11

Are you sure aren't any "strange" redirects in your Admin@index function? What your HTML source code looks like when you inspect that "a" element? Do you have a Middleware that redirects back the user if not authorized that maybe it's not working properly?

1 like

Please or to participate in this conversation.