0
我成立了新的15.2和變化後,我的路由文件看起來像這樣:Laravel5.2不需要VerifyCsrfToken
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function() {
return view('welcome');
});
Route::group(['middleware' =>'api', 'prefix' => '/api/v1'], function() {
Route::post('/api/v1/login', 'Api\V1\Auth\[email protected]');
});
當我去郵遞員,使POST:http://kumarajiva.dev/api/v1/login我得到:TokenMismatchException in VerifyCsrfToken.php line 67
但我的內核文件看起來像這樣:
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',
],
];
我什麼也沒改變。路由'登錄'在'api'middelware組(不是'web',其中是VerifyCsrfToken),但令人驚訝的是我得到了上述錯誤。所以我想知道 - wtf?它是如何工作的? '網絡'middelware組是否全部執行(針對每個請求)?
是的你有權利,我運行'php工匠路線:列表'和我所有的路線都有'網絡'middelware。這是非常違反直覺...謝謝你的答案。 –
當我從函數RouteServiceProvider @ mapWebRoutes中移除''middleware'=>'web''時,它使用'php artisan route:list'工作:) –