mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-08 14:04:50 +00:00
44 lines
852 B
PHP
44 lines
852 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Silber\Bouncer\Bouncer;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class ScopeBouncer
|
|
{
|
|
/**
|
|
* The Bouncer instance.
|
|
*
|
|
* @var Bouncer
|
|
*/
|
|
protected $bouncer;
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
public function __construct(Bouncer $bouncer)
|
|
{
|
|
$this->bouncer = $bouncer;
|
|
}
|
|
|
|
/**
|
|
* Set the proper Bouncer scope for the incoming request.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$user = $request->user();
|
|
$tenantId = $request->header('company')
|
|
? $request->header('company')
|
|
: $user->companies()->first()->id;
|
|
|
|
$this->bouncer->scope()->to($tenantId);
|
|
|
|
return $next($request);
|
|
}
|
|
}
|