ScopeBouncer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Silber\Bouncer\Bouncer;
6
7
use Closure;
8
9
class ScopeBouncer
10
{
11
    /**
12
     * The Bouncer instance.
13
     *
14
     * @var \Silber\Bouncer\Bouncer
15
     */
16
    protected $bouncer;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param \Silber\Bouncer\Bouncer  $bouncer
22
     */
23
    public function __construct(Bouncer $bouncer)
24
    {
25
        $this->bouncer = $bouncer;
26
    }
27
28
    /**
29
     * Set the proper Bouncer scope for the incoming request.
30
     *
31
     * @param  \Illuminate\Http\Request  $request
32
     * @param  \Closure  $next
33
     * @return mixed
34
     */
35
    public function handle($request, Closure $next)
36
    {
37
        // Here you may use whatever mechanism you use in your app
38
        // to determine the current tenant. To demonstrate, the
39
        // $tenantId is set here from the user's account_id.
40
        //$tenantId = $request->user()->account_id;
41
42
        //$this->bouncer->scope()->to($tenantId);
43
44
        $this->bouncer->scope()->to(request('subdomain'))->onlyRelations()->dontScopeRoleAbilities();
45
46
        return $next($request);
47
    }
48
}
49