Subdomain   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use App\Association;
7
use Illuminate\Support\Arr;
8
9
class Subdomain
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @param  \Closure  $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        \URL::defaults(['subdomain' => request('subdomain')]);
21
22
        $association = $request->route('association');
23
24
        if (!($association instanceof Association)) {
25
            // FIXME: redo routes so we always get association from there instead:
26
            $subdomain = Arr::first(explode('.', $request->getHost()));
27
28
            $association = Association::where('subdomain', $subdomain)->first();
29
        }
30
31
        \View::share('association', $association);
32
33
        return $next($request);
34
    }
35
}
36