Completed
Push — master ( 1190d4...987f57 )
by Bhavin
18s queued 11s
created

ApiHeaderInject::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
namespace Bhavingajjar\LaravelApiGenerator\Middleware;
3
4
use Closure;
5
use Illuminate\Http\Response;
6
use Illuminate\Support\Facades\Config;
7
8
class ApiHeaderInject
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        if(config('laravel-api-generator.json_response')) {
13
            $request->headers->add([
14
                'Accept'=>'application/json',
15
                'Content-Type'=>'application/json'
16
            ]);
17
        }
18
        if(config('laravel-api-generator.allow_cross_origin')) {
19
            $request->headers->add([
20
                'Access-Control-Allow-Origin' => '*',
21
                'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
22
            ]);
23
        }
24
        return $next($request);
25
    }
26
}
27