Skip to content

Commit 0845968

Browse files
Merge pull request #53 from travisaustin/master
Fixed bug when using custom UUID column and casting
2 parents 76d7dd9 + 825b3d6 commit 0845968

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/GeneratesUuid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function bootGeneratesUuid()
6161
$uuid = $uuid->fromString(strtolower($model->attributes[$model->uuidColumn()]));
6262
}
6363

64-
$model->attributes[$model->uuidColumn()] = $model->hasCast('uuid') ? $uuid->getBytes() : $uuid->toString();
64+
$model->attributes[$model->uuidColumn()] = $model->hasCast($model->uuidColumn(), 'uuid') ? $uuid->getBytes() : $uuid->toString();
6565
});
6666
}
6767

tests/Feature/UuidTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Events\Dispatcher;
1010
use Tests\Fixtures\CustomUuidPost;
1111
use Illuminate\Container\Container;
12+
use Tests\Fixtures\CustomCastUuidPost;
1213
use Illuminate\Database\Capsule\Manager;
1314

1415
class UuidTest extends TestCase
@@ -68,6 +69,14 @@ public function you_can_generate_a_uuid_without_casting()
6869
$this->assertNotNull($post->uuid);
6970
}
7071

72+
/** @test */
73+
public function you_can_generate_a_uuid_with_casting_and_a_custom_field_name()
74+
{
75+
$post = CustomCastUuidPost::create(['title' => 'test post']);
76+
77+
$this->assertNotNull($post->custom_uuid);
78+
}
79+
7180
/** @test */
7281
public function you_can_specify_a_uuid_without_casting()
7382
{

tests/Fixtures/CustomCastUuidPost.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
class CustomCastUuidPost extends Model
6+
{
7+
8+
/**
9+
* {@inheritdoc}
10+
*/
11+
protected $casts = ['custom_uuid' => 'uuid'];
12+
13+
public function uuidColumn()
14+
{
15+
return 'custom_uuid';
16+
}
17+
}

0 commit comments

Comments
 (0)