mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
Telescope tags
This commit is contained in:
parent
33d6fd82da
commit
2c1cc41b97
2 changed files with 49 additions and 0 deletions
48
src/Features/TelescopeTags.php
Normal file
48
src/Features/TelescopeTags.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue