I set up fresh L5.2 and my route files after changes looks like that:
<?php
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' =>'api', 'prefix' => '/api/v1'], function () {
Route::post('/api/v1/login', 'Api\V1\Auth\AuthController@postLogin');
});
I create controller and thats all. When i go to postman and make POST: http://myproject.dev/api/v1/login I get: TokenMismatchException in VerifyCsrfToken.php line 67.
But I don't newer use 'web' middelware group in routing file (which is definced in Kernel.php) ! So how it works? Does 'web' middelware group is executes for each request (which is counterintuitive)- or may be I do something wrong? Please help
It was removed from RouteServiceProvider so you had to explicitly assign the web middleware within routes or controllers for a while but I think it was added back in for approachability for newer people to the framework and it's usually the typical behaviour for a new project.
Remove it from your project's RouteServiceProvider and add web back into any routes or controllers where you need sessions etc
Due to your hint @aardalich I found solution: don't remove RouteServiceProvider (because then for instance php artisan route:list will not work) but instead edit in your project app/Providers/RouteServiceProvider@mapWebRoutes and remove 'middleware' => 'web', so you will get: