Skip to content

Commit

Permalink
Format path and data for views
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Aug 16, 2019
1 parent e278171 commit c4c1261
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/Watchers/ViewWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Telescope\Watchers;

use Illuminate\View\View;
use Illuminate\Support\Str;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\IncomingEntry;

Expand Down Expand Up @@ -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();
}
}

0 comments on commit c4c1261

Please sign in to comment.