diff --git a/src/Concerns/HasTelescopeTags b/src/Concerns/HasTelescopeTags new file mode 100644 index 0000000..d79feb9 --- /dev/null +++ b/src/Concerns/HasTelescopeTags @@ -0,0 +1,47 @@ +all(); + } + return collect($items) + ->map(function($item) { + if ($item instanceof \Illuminate\Database\Eloquent\Model) { + $model_tag = sprintf('%s:%s', \get_class($item), $item->getKey()); + $relationship_tags = $this->tags($item->getRelations()); + return array_merge( + [$model_tag], + [$relationship_tags] + ); + } + if (\is_iterable($item)) { + if ($item instanceof \Illuminate\Support\Enumerable) { + $item = $item->all(); + } + return $this->tags($item); + } + return null; + }) + ->flatten() // Convert nested tags to single dimensional array + ->filter() // Remove null values + ->unique() // Models might occur more than once + ->values() // Force to non-associative array + ->toArray(); + } +}