Laravel “CSRF token mismatch” for POST with laravel-cors and axios Laravel “CSRF token mismatch” for POST with laravel-cors and axios vue.js vue.js

Laravel “CSRF token mismatch” for POST with laravel-cors and axios


Please use routes/api.php for apis routing,don't use the routes/web.php for api.

If you want to use sub-domain then do required changes in following file:

app/Providers/RouteServiceProvider.php

Original:

protected function mapApiRoutes() {    Route::prefix('api')    ->middleware('api')    ->namespace($this->namespace)    ->group(base_path('routes/api.php'));}

Updated:

protected function mapApiRoutes() {    Route::domain('api.' .  env('APP_URL'))    ->middleware('api')    ->namespace($this->namespace)    ->group(base_path('routes/api.php'));}


in the address

vendor/fruitcake/laravel-cors/src/HandleCors.php

comment this

        // Check if we're dealing with CORS and if we should handle it         if (! $this->shouldRun($request)) {         return $next($request);          }