Error CORS Policy Laravel & VueJs Rest API

in laravel •  6 years ago 

cover1.jpg

Access to XMLHttpRequest at 'http://localhost:8000/api/mydata'
from origin 'http://localhost:8080' has been blocked by 
CORS policy: No 'Access-Control-Allow-Origin' 
header is present on the requested resource.

Solution:

  1. Install
$ composer require barryvdh/laravel-cors

open file Kernel.php and put \Barryvdh\Cors\HandleCors::class, on protected middleware

protected $middleware = [
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
        \Barryvdh\Cors\HandleCors::class,
    ];
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!