Skip to content

Commit

Permalink
ReflectionClass for enum detection
Browse files Browse the repository at this point in the history
  • Loading branch information
achyutkneupane committed Jan 2, 2025
1 parent 8cdefd3 commit 5170a9d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/support/src/Commands/Concerns/CanReadModelSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Support\Str;
use ReflectionClass;
use ReflectionException;
use function Illuminate\Support\enum_value;

trait CanReadModelSchemas
{
Expand Down Expand Up @@ -234,6 +233,14 @@ public function getRecordTitleAttribute(): ?string
protected function getEnumCasts($model)
{
$casts = app($model)->getCasts();
return array_filter($casts, fn ($cast) => enum_exists($cast));
return array_filter($casts, function ($cast) {

if (class_exists($cast)) {
$reflection = new \ReflectionClass($cast);
return $reflection->isEnum();
}

return false;
});
}
}

0 comments on commit 5170a9d

Please sign in to comment.