简体   繁体   中英

Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219

When I try to access a page I get MethodNotAllowedHttpException. This used to work, but can't figure out what I did to break it.

routes.php

Route::post('api', ['middleware' => 'api', 'uses' => 'DeviceController@api']);

DeviceController.php

public function api()
{
    return view('api');
}

api.blade.php (I have altered api.blade.php to rule it out as the source of the problem.)

<?php echo 'test'; ?>

app/Http/kernal.php

    protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
    ],

    'api' => [
        'throttle:60,1',
        'auth:api',
    ],
];

config/auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'devices',
    ],
],
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

    'devices' => [
        'driver' => 'eloquent',
        'model' => App\Device::class,
    ],
],

app/Providers/RouteServiceProvider.php

public function map(Router $router)
{
    $router->group([
        'namespace' => $this->namespace,
    ], function ($router) {
        require app_path('Http/routes.php');
    });
}

I am using postman to simulate POST requests.

I figured out the problem. I am forcing a secure connection with the .htaccess file while trying to use http.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM