Skip to content

Commit

Permalink
Add support for model keys cast to backed enums in FormatModel (#1286)
Browse files Browse the repository at this point in the history
* Add support for model keys casted to backed enums in FormatModel

* Fix code style

* Added interface_exists() check to avoid breaking compatibility with PHP < 8.1

* Removed import for interface BackedEnum to preserve compatibility

* Add support for Pivots with backed enum ids

* Update FormatModel.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
saadsidqui and taylorotwell authored Dec 30, 2022
1 parent 64223ee commit 3791d31
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/FormatModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Telescope;

use BackedEnum;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Arr;

Expand All @@ -24,6 +25,8 @@ public static function given($model)
$keys = $model->getKey();
}

return get_class($model).':'.implode('_', Arr::wrap($keys));
return get_class($model).':'.implode('_', array_map(function ($value) {
return $value instanceof BackedEnum ? $value->value : $value;
}, Arr::wrap($keys)));
}
}

0 comments on commit 3791d31

Please sign in to comment.