mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
v5.0.0 update
This commit is contained in:
45
app/Http/Middleware/ScopeBouncer.php
Normal file
45
app/Http/Middleware/ScopeBouncer.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Silber\Bouncer\Bouncer;
|
||||
|
||||
class ScopeBouncer
|
||||
{
|
||||
/**
|
||||
* The Bouncer instance.
|
||||
*
|
||||
* @var \Silber\Bouncer\Bouncer
|
||||
*/
|
||||
protected $bouncer;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \Silber\Bouncer\Bouncer $bouncer
|
||||
*/
|
||||
public function __construct(Bouncer $bouncer)
|
||||
{
|
||||
$this->bouncer = $bouncer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the proper Bouncer scope for the incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$user = $request->user();
|
||||
$tenantId = $request->header('company')
|
||||
? $request->header('company')
|
||||
: $user->companies()->first()->id;
|
||||
|
||||
$this->bouncer->scope()->to($tenantId);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user