Skip to content

Commit

Permalink
fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
alsofronie committed Jul 20, 2017
1 parent 2043e27 commit 90e5a41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/UuidBinaryModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ private function deepArray($array)
$useOptimization = !empty($this->uuidOptimization);
foreach ($array as $key => $value) {
if (!is_string($value)) {
$array[$key] = $this->deepArray((array)$value);
if (is_object($value) && method_exists($value, 'toArray')) {
$array[$key] = $value->toArray();
} else {
$array[$key] = $this->deepArray((array)$value);
}
} elseif (!ctype_print($value)) {
$array[$key] = $useOptimization ? self::toNormal($value) : bin2hex($value);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/EloquentUuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,23 @@ public function testJsonCustomAtributesBinary()
static::assertNotNull($json);
}

public function testToArray()
{
$model = EloquentBinOptimizedUserModel::create([
'username' => 'Model',
'password' => 'secret'
]);
$customModel = EloquentBinOptimizedPostModel::create(['name' => 'bla']);
$model->cust = $customModel;

$array = $model->toArray();
static::assertNotNull($array);

$json = json_encode($array);
var_dump($json);
static::assertNotNull($json);
}

/**
* Bootstrap Eloquent.
*
Expand Down

0 comments on commit 90e5a41

Please sign in to comment.