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

Chris1904's avatar

When routes URL is admin it results in 404

Hi!

For some odd reason if I try to view the admin route it results in in 404 error.

Route::get('admin', function () {
    return view('admin.index');
});

If I rename the URL to anything else, it works as expected and it displayed the view.

Have you guys ever experienced something like this? I use Laravel Valet and I would to know how this could be solved.

Thanks!

0 likes
12 replies
DuikGek's avatar

what is the name of your view blade?

if your blade call index.blade than you can do that

Route::get('/index', function () {
return view('index');
 });

and your url the name.dev/index

if your blade in directory call admin than

Route::get('index', function () {
return view('admin/index');
});

url is the same as above

Chris1904's avatar

My blade file is stored in admin/index.blade.php and there is no problem with it. As I mentioned, if I rename

Route::get('admin', function () {
    return view('admin.index');
});

to

Route::get('admins', function () {
    return view('admin.index');
});

it will work just fine. Accessing mysite.dev/admin just results in a 404. Even changing the URL to admin/index will work, but I am curious as to why the admin URL does not.

DuikGek's avatar

try to use

Route::get('admin', function () {
return view('admin.index')->name('admin');
});
Snapey's avatar

Do you have an admin route prefix?

run php artisan route:list and check

Chris1904's avatar

Thanks Snapey. Looks correct to me as well :-(

+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                    | Name             | Action                                                                 | Middleware   |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      | home             | App\Http\Controllers\HomeController@index                              | web          |
|        | GET|HEAD | admin                  |                  | Closure                                                                | web          |
|        | GET|HEAD | api/user               |                  | Closure                                                                | api,auth:api |
|        | GET|HEAD | login                  | login            | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                  |                  | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                 | logout           | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         |                  | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |                  | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
Snapey's avatar
Snapey
Best Answer
Level 122

do you have a folder called admin in your public folder?

3 likes
Chris1904's avatar

Wow, not sure how I missed that. Thank you sooooooo much!!!

mechtech5's avatar

thanks, man! I ran into the same error today glad that I found this thread...

loqman's avatar
                                    for admin Auth

step1:

inter into terminal php artisan make:middleware IsAdmin.

please be create field IsAdmin to user at default ->0 if be admin ->1

1 like

Please or to participate in this conversation.