-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy pathScopeBouncer.php
42 lines (35 loc) · 895 Bytes
/
ScopeBouncer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace App\Http\Middleware;
use Closure;
use Silber\Bouncer\Bouncer;
class ScopeBouncer
{
/**
* The Bouncer instance.
*
* @var \Silber\Bouncer\Bouncer
*/
protected $bouncer;
/**
* Constructor.
*/
public function __construct(Bouncer $bouncer)
{
$this->bouncer = $bouncer;
}
/**
* Set the proper Bouncer scope for the incoming request.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function handle($request, Closure $next)
{
// Here you may use whatever mechanism you use in your app
// to determine the current tenant. To demonstrate, the
// $tenantId is set here from the user's account_id.
$tenantId = $request->user()->account_id;
$this->bouncer->scope()->to($tenantId);
return $next($request);
}
}