Skip to content

Commit

Permalink
formatting view data
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Nov 8, 2018
1 parent ec09107 commit 7183e58
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Watchers/RequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\IncomingEntry;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Foundation\Http\Events\RequestHandled;

Expand Down Expand Up @@ -113,7 +114,9 @@ protected function response(Response $response)

$originalContent = $response->getOriginalContent();

return $originalContent instanceof View ? ['view' => $originalContent->name(), 'path' => $originalContent->getPath(), 'data' => $originalContent->getData()] : 'HTML Response';
return $originalContent instanceof View
? ['view' => $originalContent->getPath(), 'data' => $this->extractDataFromView($originalContent)]
: 'HTML Response';
}

/**
Expand All @@ -128,4 +131,26 @@ public function contentWithinLimits($content)

return mb_strlen($content) / 1000 <= $limit;
}

/**
* Extract the data from the given view in array form.
*
* @param \Illuminate\View\View $view
* @return array
*/
protected function extractDataFromView($view)
{
return collect($view->getData())->map(function ($value) {
if ($value instanceof Model) {
return get_class($value).':'.$value->getKey();
} elseif (is_object($value)) {
return [
'class' => get_class($value),
'properties' => json_decode(json_encode($value), true),
];
} else {
return json_decode(json_encode($value), true);
}
})->toArray();
}
}

0 comments on commit 7183e58

Please sign in to comment.