| Conditions | 7 |
| Paths | 13 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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('frontarea.home'), |
||
| 27 | 'with' => ['warning' => trans('cortex/foundation::messages.resource_not_found', ['resource' => trans('cortex/tenants::common.tenant'), 'identifier' => $subdomain])], |
||
| 28 | ]); |
||
| 29 | } |
||
| 30 | |||
| 31 | // Scope bouncer |
||
| 32 | (! $tenant || ! app()->bound(\Silber\Bouncer\Bouncer::class)) || app(\Silber\Bouncer\Bouncer::class)->scope()->to($tenant->getKey()); |
||
| 33 | |||
| 34 | // unBind {subdomain} route parameter |
||
| 35 | ! $request->route('subdomain') || $request->route()->forgetParameter('subdomain'); |
||
| 36 | |||
| 37 | // Activate current tenant |
||
| 38 | ! $tenant || config(['rinvex.tenants.active' => $tenant]); |
||
| 39 | |||
| 40 | return $next($request); |
||
| 41 | } |
||
| 42 | } |
||
| 43 |