Completed
Push — develop ( fce6a6...d243d8 )
by Abdelrahman
03:57
created

Tenantable::handle()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 10
nc 5
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\Http\Middleware;
6
7
use Closure;
8
9
class Tenantable
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param \Illuminate\Http\Request $request
15
     * @param \Closure                 $next
16
     *
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        $subdomain = $request->route('subdomain');
22
        $tenant = app('rinvex.tenants.tenant')->where('slug', $subdomain)->first();
23
24
        if ($subdomain && ! $tenant) {
25
            return intend([
26
                'url' => route('guestarea.home'),
27
                'with' => ['warning' => trans('cortex/tenants::messages.tenant.not_found', ['tenantSlug' => $subdomain])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
28
            ]);
29
        }
30
31
        // unBind {subdomain} route parameter
32
        ! $request->route('subdomain') || $request->route()->forgetParameter('subdomain');
33
34
        // Activate current tenant
35
        ! $tenant || config(['rinvex.tenants.tenant.active' => $tenant]);
36
37
        return $next($request);
38
    }
39
}
40