From 060a4bc5255fa110f362e9cdd1fd3ce087a9744c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 17 Aug 2019 22:18:42 +0200 Subject: [PATCH] wip --- src/Middleware/InitializeTenancy.php | 13 ------------- src/TenancyServiceProvider.php | 23 +++++++++++++++++++++++ tests/TelescopeTest.php | 3 +++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Middleware/InitializeTenancy.php b/src/Middleware/InitializeTenancy.php index 0a2e2ae3..c0539eb6 100644 --- a/src/Middleware/InitializeTenancy.php +++ b/src/Middleware/InitializeTenancy.php @@ -29,19 +29,6 @@ class InitializeTenancy ($this->onFail)($e); } - if (class_exists(Telescope::class)) { - $original_callback = Telescope::tagUsing; - - Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) use ($original_callback) { - $tags = []; - if (tenancy()->initialized) { - $tags = ['tenant:' . tenant('uuid')]; - } - - return array_merge($original_callback($entry), $tags); - }); - } - return $next($request); } } diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 76218665..ff734b64 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -3,6 +3,7 @@ namespace Stancl\Tenancy; use Stancl\Tenancy\Commands\Run; +use Laravel\Telescope\Telescope; use Stancl\Tenancy\Commands\Seed; use Illuminate\Cache\CacheManager; use Stancl\Tenancy\Commands\Install; @@ -43,6 +44,28 @@ class TenancyServiceProvider extends ServiceProvider ]); $this->app->register(TenantRouteServiceProvider::class); + + if (class_exists(Telescope::class)) { + $this->setTelescopeTags(); + } + } + + public function setTelescopeTags() + { + $original_callback = Telescope::$tagUsing; + + Telescope::tag(function (\Laravel\Telescope\IncomingEntry $entry) use ($original_callback) { + $tags = []; + if (! is_null($original_callback)) { + $tags = $original_callback($entry); + } + + if (in_array('tenancy', request()->route()->middleware())) { + $tags = array_merge($tags, ['tenant:' . tenant('uuid')]); + } + + return $tags; + }); } /** diff --git a/tests/TelescopeTest.php b/tests/TelescopeTest.php index 2a7f997b..23357df7 100644 --- a/tests/TelescopeTest.php +++ b/tests/TelescopeTest.php @@ -6,6 +6,9 @@ use Illuminate\Support\Facades\Artisan; class TelescopeTest extends TestCase { + public $autoCreateTenant = false; + public $autoInitTenancy = false; + public function setUp(): void { Artisan::call('telescope:install');