Skip to content

Commit

Permalink
fix: add support for enum casts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Jul 25, 2023
1 parent fab8cd6 commit d5670e3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Drivers/FileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orbit\Drivers;

use BackedEnum;
use FilesystemIterator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -85,7 +86,15 @@ public function filepath(string $directory, string $key): string
protected function getModelAttributes(Model $model)
{
return collect($model->getAttributes())
->map(fn ($_, $key) => $model->{$key})
->map(function ($_, $key) use ($model) {
$value = $model->{$key};

if ($value instanceof BackedEnum) {
return $value->value;
}

return $value;
})
->toArray();
}

Expand Down

0 comments on commit d5670e3

Please sign in to comment.