title: How to enable CORS in Laravel?
body: <p>I am in Laravel 5.8  - I kept getting this CORS issue</p>
  
  <p><img src="https://i.imgur.com/oAeTL5d.png" alt=""></p>
  
  <p>I've tried </p>
  
  <pre><code>php artisan make:middleware Cors
  </code></pre>
  
  <p>Add these code </p>
  
  <pre><code>&lt;?php
  namespace App\Http\Middleware;
  use Closure;
  class Cors
  {
    public function handle($request, Closure $next)
    {
      return $next($request)
        -&gt;header(‘Access-Control-Allow-Origin’, ‘*’)
        -&gt;header(‘Access-Control-Allow-Methods’, ‘GET, POST, PUT, DELETE, OPTIONS’)
        -&gt;header(‘Access-Control-Allow-Headers’, ‘X-Requested-With, Content-Type, X-Token-Auth, Authorization’);
    }
  }
  </code></pre>
  
  <p>restart my local Apache 2 <code>sudo apachectl -k restart</code></p>
  
  <p>Open up <code>app/Http/Kernel.php</code> - added this 1 line </p>
  
  <pre><code>protected $routeMiddleware = [
          'auth' =&gt; \Illuminate\Auth\Middleware\Authenticate::class,
          'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
          'bindings' =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
          'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,
          'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
          'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
          'admin' =&gt; \App\Http\Middleware\AdminMiddleware::class,
          'dev' =&gt; \App\Http\Middleware\DevMiddleware::class,
          'cors' =&gt; \App\Http\Middleware\Cors::class, &lt;----- 
      ];
  </code></pre>
  
  <p>refresh the site, go to console, still see the same CORS issue </p>
  
  <p>How would one go about and debug this further?</p>