Home > Software engineering >  Laravel returns 404 status on all controllers except the root page /
Laravel returns 404 status on all controllers except the root page /

Time:12-26

Сlean laravel and for some reason only returns 200 status on the root page. On other routes, I get a 404 status, and not a specially designed page for a 404 error, but a regular one in which the response sent by the controller is displayed. I can't understand what the problem is, what options could there be?

in routes/web.php

Route::get('/home', function () {
    return response('Hello World', 200)
                  ->header('Content-Type', 'text/plain');
});


Route::get('/duck', function () {
    return [1, 2, 3];
});

CodePudding user response:

First I would check if all routes are registered. you do that with php artisan route:list. If not, then enter php artisan route:clear.

If that not helps you can try: php artisan config:cache

CodePudding user response:

Thank you all for your help, the error was in the nginx configuration the part was missing. If this code is not there, then all routes except the root will be 404. There will also be a problem with route caching, you will need to clear the cache very often after editing routes/web.php

location / {
        try_files $uri $uri/ /index.php?$query_string;
}
  • Related