From c4c126113a4545ca0aea869d453a9fcf07a289c8 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 16 Aug 2019 09:37:55 +0200 Subject: [PATCH] Format path and data for views --- src/Watchers/ViewWatcher.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Watchers/ViewWatcher.php b/src/Watchers/ViewWatcher.php index 01756dc51..0bfdb1459 100644 --- a/src/Watchers/ViewWatcher.php +++ b/src/Watchers/ViewWatcher.php @@ -3,6 +3,7 @@ namespace Laravel\Telescope\Watchers; use Illuminate\View\View; +use Illuminate\Support\Str; use Laravel\Telescope\Telescope; use Laravel\Telescope\IncomingEntry; @@ -37,8 +38,39 @@ public function recordAction($event, $data) Telescope::recordView(IncomingEntry::make(array_filter([ 'name' => $view->getName(), - 'path' => $view->getPath(), - 'data' => array_keys($view->getData()), + 'path' => $this->extractPath($view), + 'data' => $this->extractKeysFromData($view), ]))); } + + /** + * Extract the path from the given view. + * + * @param \Illuminate\View\View $view + * @return string + */ + protected function extractPath($view) + { + $path = $view->getPath(); + + if (Str::startsWith($path, base_path())) { + $path = substr($path, strlen(base_path())); + } + + return $path; + } + + + /** + * Extract the keys from the given view in array form. + * + * @param \Illuminate\View\View $view + * @return array + */ + protected function extractKeysFromData($view) + { + return collect($view->getData())->filter(function ($value, $key) { + return ! in_array($key, ['app', '__env', 'obLevel', 'errors']); + })->keys(); + } }