404 Not Found, but route exist in Laravel 5.4
Solution 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.
Solution 2:
Please make sure you have Apache configured with the following information in /path/to/apache2/installation/conf/httpd.conf
<Directory "path/to/laravel/project/public">
Allowoverride All
</Directory>
For the .htaccess
file located in the public/
folder, make sure it includes 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>
Then enable the Apache mod_rewrite
module:
sudo a2enmod rewrite
Solution 3:
I had the same Issue & resolved it by changing the way Routes were ordered.
Before:
Route::get('/p/{post}', 'PostsController@show');
Route::get('/p/create', 'PostsController@create');
After: (and that 404 disappeared)
Route::get('/p/create', 'PostsController@create');
Route::get('/p/{post}', 'PostsController@show');
Solution 4:
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/*'
];
}