Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit cce671c

Browse files
Merge pull request #34 from michaeldyrynda/feature/nullable-uuids
Handle an empty UUID value, allowing nullable UUIDs
2 parents e7a06c3 + 9ef103d commit cce671c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Casts/EfficientUuid.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Dyrynda\Database\Casts;
44

5-
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
65
use Ramsey\Uuid\Uuid;
6+
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
77

88
class EfficientUuid implements CastsAttributes
99
{
@@ -18,6 +18,10 @@ class EfficientUuid implements CastsAttributes
1818
*/
1919
public function get($model, string $key, $value, array $attributes)
2020
{
21+
if (trim($value) === '') {
22+
return;
23+
}
24+
2125
return Uuid::fromBytes($value)->toString();
2226
}
2327

@@ -32,6 +36,10 @@ public function get($model, string $key, $value, array $attributes)
3236
*/
3337
public function set($model, string $key, $value, array $attributes)
3438
{
39+
if (trim($value) === '') {
40+
return;
41+
}
42+
3543
return [
3644
$key => Uuid::fromString(strtolower($value))->getBytes(),
3745
];

0 commit comments

Comments
 (0)