1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 18:04:03 +00:00

Telescope tags

This commit is contained in:
Samuel Štancl 2020-05-21 18:05:02 +02:00
parent 33d6fd82da
commit 2c1cc41b97
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Features;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Tenancy;
class TelescopeTags implements Feature
{
/** @var callable User-specific callback that returns tags. */
public static $getTagsUsing;
public function bootstrap(Tenancy $tenancy): void
{
if (! class_exists(Telescope::class)) {
return;
}
Telescope::tag(function (IncomingEntry $entry) {
$tags = $this->getTags($entry);
if (! request()->route()) {
return $tags;
}
if (tenancy()->initialized) {
$tags = array_merge($tags, [
'tenant:' . tenant('id'),
]);
}
return $tags;
});
}
public static function getTags(IncomingEntry $entry): array
{
$callback = static::$getTagsUsing ?? function () {
return [];
};
return $callback($entry);
}
}