Skip to content

Commit

Permalink
Merge pull request #425 from laravel/formatModelString
Browse files Browse the repository at this point in the history
Format model string
  • Loading branch information
themsaid authored Nov 21, 2018
2 parents 938b5f6 + 45db70c commit 85c28ad
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ExtractProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function from($target)
$property->setAccessible(true);

if (($value = $property->getValue($target)) instanceof Model) {
return [$property->getName() => get_class($value).':'.$value->getKey()];
return [$property->getName() => FormatModel::given($value)];
} elseif (is_object($value)) {
return [
$property->getName() => [
Expand Down
6 changes: 3 additions & 3 deletions src/ExtractTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function from($target)
}

return static::modelsFor([$target])->map(function ($model) {
return get_class($model).':'.$model->getKey();
return FormatModel::given($model);
})->all();
}

Expand All @@ -44,7 +44,7 @@ public static function fromJob($job)
}

return static::modelsFor(static::targetsFor($job))->map(function ($model) {
return get_class($model).':'.$model->getKey();
return FormatModel::given($model);
})->all();
}

Expand All @@ -65,7 +65,7 @@ public static function fromArray(array $data)
})->collapse()->filter();

return $models->map(function ($model) {
return get_class($model).':'.$model->getKey();
return FormatModel::given($model);
})->all();
}

Expand Down
20 changes: 20 additions & 0 deletions src/FormatModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Laravel\Telescope;

use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;

class FormatModel
{
/**
* Format the given model to a readable string.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return array
*/
public static function given($model)
{
return get_class($model).':'.implode('_', Arr::wrap($model->getKey()));
}
}
3 changes: 2 additions & 1 deletion src/Watchers/ModelWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class ModelWatcher extends Watcher
Expand Down Expand Up @@ -32,7 +33,7 @@ public function recordAction($event, $data)
return;
}

$model = get_class($data[0]).':'.implode('_', (array) $data[0]->getKey());
$model = FormatModel::given($data[0]);

$changes = $data[0]->getChanges();

Expand Down
3 changes: 2 additions & 1 deletion src/Watchers/NotificationWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Laravel\Telescope\Telescope;
use Laravel\Telescope\ExtractTags;
use Laravel\Telescope\FormatModel;
use Laravel\Telescope\IncomingEntry;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -62,7 +63,7 @@ private function tags($event)
private function formatNotifiable($notifiable)
{
if ($notifiable instanceof Model) {
return get_class($notifiable).':'.$notifiable->getKey();
return FormatModel::given($notifiable);
} elseif ($notifiable instanceof AnonymousNotifiable) {
return 'Anonymous:'.implode(',', $notifiable->routes);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Watchers/RequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\FormatModel;
use Laravel\Telescope\IncomingEntry;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -171,7 +172,7 @@ protected function extractDataFromView($view)
{
return collect($view->getData())->map(function ($value) {
if ($value instanceof Model) {
return get_class($value).':'.$value->getKey();
return FormatModel::given($value);
} elseif (is_object($value)) {
return [
'class' => get_class($value),
Expand Down

0 comments on commit 85c28ad

Please sign in to comment.