404 Not Found, but route exist in Laravel 5.4

2020-06-30 05:32发布

I'm using PhpStorm. I can run and open the index.php, but when I want to press submit button (post sign in), its display 404 not found.

Web server Apache 2.4 running on Windows 10.

This is my home

index.php

This is my route

web.php

13条回答
仙女界的扛把子
2楼-- · 2020-06-30 05:56

Update 2020
There are many case happened above, I've once more case I met a long time but I still forget and sometimes I dont know why. This is some url patterns is the same, example abc.com/c/{get_an_id} and abc.com/c/get_text. You can change order but only first can run, 404 for the second url.

查看更多
爷的心禁止访问
3楼-- · 2020-06-30 05:58

I'm not entirely sure why all the down-votes, especially since this is a common issue and the cause can be hidden for someone new to the Laravel environment. I know this is an old post, but I add it here for future newbies.

The first thing I suggest trying is running php artisan route:list from the command line (from your project root directory). This will list all the routes that Laravel can register and if there are any errors, usually they will show up here.

The second thing I suggest is to ensure that the URL matches route. I can't tell you how many times I've tried to figure out why my route was returning a 404 simply because my form was posting to something like /insertStudent when my route was defined as /admin/insertStudent

The third thing I suggest is to ensure the method you are calling exists. Are your methods really called postSignIn and postInsertStudent and not simply SignIn and InsertStudent? Keep in mind that both the URL and method names are case sensitive and should match where you define the route, the URL that is being called, and the method that is receiving the request.

Finally if all that checks out, one last thing I might suggest you try is running php artisan route:clear. This resets the route cache.

查看更多
姐就是有狂的资本
4楼-- · 2020-06-30 05:59

dontforget, the url is sensitive case to the folder name

查看更多
戒情不戒烟
5楼-- · 2020-06-30 06:00

Don't forget the order of your routes. For example, if you want to go to /path/second and have the following routes registered:

Route::get('/path/{dynamic_second}', 'Controller@actionDynamic');

Route::get('/path/{dynamic_second}/{dynamic_third}', 'Controller@third');

Route::get('/path/second', 'Controller@action');

This will break, as second is consumed by /path/{dynamic_second}.

If you want to access /path/second, you have to have your routes listed like so:

Route::get('/path/second', 'Controller@action');

Route::get('/path/{dynamic_second}', 'Controller@actionDynamic');

Route::get('/path/{dynamic_second}/{dynamic_third}', 'Controller@third');
查看更多
【Aperson】
6楼-- · 2020-06-30 06:09

make sure, the url passed is equal in your route. check the parameters and action in the form. To get clear answer post your mvc

查看更多
叛逆
7楼-- · 2020-06-30 06:11

Make sure you added correct Accept header.

In my case I tried to access api endpoints and each time recieved 404 resource not found. When I've added Accept: application/json header I got response from matched route

查看更多
登录 后发表回答