Skip to content

Commit

Permalink
Cast Carbon instances to string in toArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiCollin committed May 6, 2015
1 parent e6e6ed6 commit 5b24de4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Analogue\ORM\System\ProxyInterface;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Carbon\Carbon;

class ValueObject implements Mappable, ArrayAccess, Jsonable, JsonSerializable, Arrayable {
use MappableTrait;
Expand Down Expand Up @@ -147,6 +148,12 @@ protected function attributesToArray(array $sourceAttributes)
// it from the returned set.
if ($attribute instanceof ProxyInterface && ! $attribute->isLoaded()) continue;

if ($attribute instanceof Carbon)
{
$attributes[$key] = $attribute->toString();
continue;
}

if ($attribute instanceof Arrayable)
{
$attributes[$key] = $attribute->toArray();
Expand Down

0 comments on commit 5b24de4

Please sign in to comment.