1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| <?php
|
| namespace App\Http\Middleware;
|
| use Closure;
|
| class Cors
| {
| public function handle($request, Closure $next)
| {
| header('Access-Control-Allow-Origin: *');
|
| $headers = [
| 'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
| 'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'
| ];
| if($request->getMethod() == "OPTIONS") {
| return Response::make('OK', 200, $headers);
| }
|
| $response = $next($request);
| foreach($headers as $key => $value)
| $response->header($key, $value);
| return $response;
| }
| }
|
|