Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from michaeldyrynda/feature/nullable-uuids
Browse files Browse the repository at this point in the history
Handle an empty UUID value, allowing nullable UUIDs
  • Loading branch information
michaeldyrynda authored Aug 9, 2020
2 parents e7a06c3 + 9ef103d commit cce671c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Casts/EfficientUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Dyrynda\Database\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Ramsey\Uuid\Uuid;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class EfficientUuid implements CastsAttributes
{
Expand All @@ -18,6 +18,10 @@ class EfficientUuid implements CastsAttributes
*/
public function get($model, string $key, $value, array $attributes)
{
if (trim($value) === '') {
return;
}

return Uuid::fromBytes($value)->toString();
}

Expand All @@ -32,6 +36,10 @@ public function get($model, string $key, $value, array $attributes)
*/
public function set($model, string $key, $value, array $attributes)
{
if (trim($value) === '') {
return;
}

return [
$key => Uuid::fromString(strtolower($value))->getBytes(),
];
Expand Down

0 comments on commit cce671c

Please sign in to comment.