Symfony\Component\HttpKernel\Exception\NotFoundHttpException Laravel

前端 未结 9 1384
情话喂你
情话喂你 2020-12-01 04:37

I am trying to use RESTful controller. Here is my Route.php:

Route::resource(\'test\', \'TestController\');
Route::get(\'/\', function()
{
    r         


        
相关标签:
9条回答
  • 2020-12-01 05:10

    another thing to check is your document root,

    mine was:

    www/var

    and should be:

    www/var/mysite/public

    Another reason why I hate web development

    0 讨论(0)
  • 2020-12-01 05:11

    Before my web.php was like below

    Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
            Route::resource('roles','Admin\RoleController');
            Route::resource('users','Admin\UserController');
        });
    

    In url enterd

    http://127.0.0.1:8000/admin/roles

    and get the same error. The solution was :

    Route::group(['middleware' => ['role:admin']], function() {
      Route::resource('roles','Admin\RoleController');
      Route::resource('users','Admin\UserController');
    });
    

    Remove 'prefix' => 'admin', as both Controllers are located in Admin folder

    0 讨论(0)
  • 2020-12-01 05:11

    Put this in root .htaccess file

    The below code do three things :

    1. Remove index.php from url .
    2. Remove public from url .
    3. fix your problem .

    Note : RewriteRule ^ index.php [L] this code solve your problem my problem was not added [L] after index.php

    RewriteEngine On
    <IfModule mod_rewrite.c>
     #Session timeout
    
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
       Options +FollowSymlinks
       RewriteEngine On
    
       # Redirect Trailing Slashes...
       RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    
    </IfModule>
    
    0 讨论(0)
  • 2020-12-01 05:12

    In my case the problem was that i called the wrong route in postman.

    Wrong route : http://localhost:8000/methodName

    Correct route : http://localhost:8000/api/methodName

    I forgot to add "/api".

    0 讨论(0)
  • 2020-12-01 05:19

    I have found another situation where this error can occur, and that one has nothing todo with rewrites, for once. It's a very nasty typo :)

    I had:

    Route::get('replicas/item/{id}/{?stub}', ['uses' => 'ProductReplicasController@productview', 'as' => 'database.replicas.productview']);

    see the {?stub}, that caused this error with me, it needs to be {stub?} off course. But if you're new to Laravel (like me), that is very easy to miss and could take quite some time to figure out. :)

    0 讨论(0)
  • 2020-12-01 05:27

    like Arjan Koole says, I had a similar error

    using:

    Route::get('/performance/{$submit_type}/{$send_selected}/{$date_a}/{$date_b}', 'PerformanceController@calc');
    

    instead of

    Route::get('/performance/{submit_type}/{send_selected}/{date_a}/{date_b}', 'PerformanceController@calc');
    

    So be aware when you use {$stuff}

    0 讨论(0)
提交回复
热议问题