Laravel 5 CORS Middleware

1. Add on /app/Http/Kernel.php

protected $routeMiddleware = [
    ...
    'cors' => \App\Http\Middleware\CORS::class,
];

2. Create new file /var/www/html/DeporwinAPIConnector/app/Http/Middleware/CORS.php

<?php namespace App\Http\Middleware;

use Closure;

class CORS {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
    }

}

3. Apply the middleware for your routes

Route::get('some-path',
    array(
        'middleware' => 'cors', 
        'uses' => 'SomeContrller@someMethod'
    )
);