0
當我嘗試訪問一個頁面時,我得到MethodNotAllowedHttpException。這曾經工作,但無法弄清楚我做了什麼來打破它。Laravel 5:RouteCollection.php中的MethodNotAllowedHttpException行219
routes.php文件
Route::post('api', ['middleware' => 'api', 'uses' => '[email protected]']);
DeviceController.php
public function api()
{
return view('api');
}
api.blade.php(我已經改變api.blade.php排除它作爲問題的來源)。
<?php echo 'test'; ?>
應用程序/ 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',
],
];
配置/ 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,
],
],
應用/供應商/ RouteServiceProvider.php
public function map(Router $router)
{
$router->group([
'namespace' => $this->namespace,
], function ($router) {
require app_path('Http/routes.php');
});
}
我使用郵遞員來模擬POST請求。
從哪裏呼叫路線?看起來你正在調用'post'路由來獲取'get'路由資源。所以,這是給你的問題。 – PaladiN
@PaladiN我使用Postman(chrome pulgin)通過POST請求訪問http:// localhost/api – meeeee
因此,您是否在訪問api路由時完成了身份驗證?因爲它使用'api'中間件。你也可以發佈你的錯誤截圖。 – PaladiN