404 Not Found, but route exist in Laravel 5.4

≯℡__Kan透↙ 提交于 2020-01-24 02:06:18

问题


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

This is my route


回答1:


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.




回答2:


I had the same issue and fixed by following

I have edit .htaccess file

RewriteEngine On
RewriteBase /path/of/project/folder/
# change above to your site i.e.,  RewriteBase /whatever/public/

Hope it will work for you




回答3:


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




回答4:


This is old question but is active yet. for windows users if you using CAPITAL characters (upper-case letter) in your project folder you should using same in your browser. If your project is in "c:\xampp\htdocs\MyProject\" you should using MyProject as url instead of myproject for example in the above project (MyProject) following route:

Route::get('/dashboard', function () {
    return 'welcome to dashboard!';
});

will work if you use:

http://MyProject/dashboard

but is better using lowercase characters in directories




回答5:


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




回答6:


dontforget, the url is sensitive case to the folder name




回答7:


Changing the server port worked for me after trying several fixes all to no avail. I was running on loalhost:3000 and changed to localhost:4000. I think this might have to do with some memory cahe




回答8:


Please Make you have Apache configured with the following information

in /path/to/apache2/installation/conf/httpd.conf

Add the following information

<Directory "path/to/laravel/project/public">
    Allowoverride All
</Directory>

.htaccess file located in public folder make sure that it has the following

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
       Options -MultiViews
   </IfModule>
   Options +FollowSymlinks
   RewriteEngine On

   # Redirect Trailing Slashes...
   RewriteRule ^(.*)/$ /$1 [L,R=301]

   # Handle Front Controller...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
</IfModule>



回答9:


I had the same issue recently and I thought I was using a Reserved word, which I couldn't find in the list of reserved words of PHP.

Originally my Routes/web.php was:

Route::post('sysinfo/store',['as'=>'sysinfo.store', 'uses'=>'SysinfoController@store']);

After I changed to another name as shown bellow, it worked!

Route::post('newsysinfo/store',['as'=>'newsysinfo.store',   'uses'=>'SysinfoController@store']);

What's weird is that I have other working routes such as:

Route::get('sysinfo/',['as'=>'sysinfo.index',   'uses'=>'SysinfoController@index']);
Route::post('sysinfo/{sysinfo}',['as'=>'sysinfo.update',   'uses'=>'SysinfoController@update']);
Route::get('sysinfo/create',['as'=>'sysinfo.create',   'uses'=>'SysinfoController@create']);
Route::get('sysinfo/{id}/edit',['as'=>'sysinfo.edit',   'uses'=>'SysinfoController@edit']);
Route::get('sysinfo/{sysinfo}/destroy',['as'=>'sysinfo.destroy',   'uses'=>'SysinfoController@destroy']);

Although it's not an explanation of the causes of the problem, perhaps this workaround can help you.




回答10:


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');



回答11:


try

php artisan route:clear
php artisan route:cache

and then type this and see whether your route exists in the list

php artisan route:list

and also in Middleware\VerifyCsrfToken.php check post routes are allowed


class VerifyCsrfToken extends Middleware {

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*'
    ];

}



来源:https://stackoverflow.com/questions/43715106/404-not-found-but-route-exist-in-laravel-5-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!