<?php | |
namespace App\Http\Middleware; | |
use App\User; | |
use Auth; | |
use Closure; | |
use HipsterJazzbo\Landlord\Facades\Landlord; | |
class TenantScope | |
{ | |
public function handle($request, Closure $next) | |
{ | |
// If user is logged in, fetch associated tenant model | |
if (Auth::check()) { | |
$tenant = Auth::user()->tenant; | |
if ($tenant != null) { | |
// This will cause all models to be scoped to that tenant | |
Landlord::addTenant('tenant_id', $tenant->id); | |
} | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment