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 06:13

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.

查看更多
唯我独甜
3楼-- · 2020-06-30 06:16

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

查看更多
可以哭但决不认输i
4楼-- · 2020-06-30 06:16

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>

Remember to enable mod_rewrite module

sudo a2enmod rewrite
查看更多
看我几分像从前
5楼-- · 2020-06-30 06:16

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

查看更多
相关推荐>>
6楼-- · 2020-06-30 06:17

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/*'
    ];

}

查看更多
7楼-- · 2020-06-30 06:17

I had the same Issue & resolved it by changing the way I ordered the Routes

This is before

Route::get('/p/{post}', 'PostsController@show');
Route::get('/p/create', 'PostsController@create');

This is after (and the that 404 disappeared)

Route::get('/p/create', 'PostsController@create');
Route::get('/p/{post}', 'PostsController@show');
查看更多
登录 后发表回答