Laravel “CSRF token mismatch” for POST with laravel | laravel vue axios csrf
Ihaveadomain_ArunningLaravel5.8enginetoreturnAPIonwebroute.Itmustcheckoriginstoletservejustafewdomains,includeddomain_B.Barryvdh/laravel-corsIinstalledbarryvdh/laravel-cors[1]bycomposerandconfigureditgloballyupdatingtheKernel.php.Thisshouldworksonwebroutetoo.kernel.phpprotected$middleware=[...BarryvdhCorsHandleCors::class,];ThenIconfigtheLaravelCorsusingthestandardconfigurationastesttoallowanydomain./config/cors.phpreturn[supportsCredentials=>false,allowedOrigins=>[http:www.domain_b.co...
I have a domain_A running Laravel 5.8 engine to return API on web route. It must check origins to let serve just a few domains, included domain_B.
Barryvdh/laravel-corsI installed barryvdh/laravel-cors[1] by composer and configured it globally updating the Kernel.php. This should works on web route too.
kernel.php
protected $middleware = [ ... BarryvdhCorsHandleCors::class, ];Then I config the Laravel Cors using the standard configuration as test to allow any domain.
/config/cors.php
return [ supportsCredentials => false, allowedOrigins => [http:www.domain_b.com,https:www.domain_b.com,http:domain_b.com], allowedHeaders => [Access-Control-Allow-Origin, X-CSRF-TOKEN, Content-Type, X-Requested-With], allowedMethods => [*], // ex: [GET, POST, PUT, DELETE] exposedHeaders => [], maxAge => 0, ];The axios config is:
(domain_a)/ Repository.js
import axios from...