Skip to content

Commit 153136c

Browse files
authored
Update Arrayable.php
1 parent 0c40b64 commit 153136c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Traits/Arrayable.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@ trait Arrayable
1010

1111
public static function makeAttribute(array $attributes = [])
1212
{
13-
$instance = new static();
13+
$instance = new class implements \ArrayAccess
14+
{
15+
use Arrayable;
16+
};
1417

15-
$instance->attributes = $attributes;
18+
$instance->setAttributes($attributes);
1619

1720
return $instance;
1821
}
1922

23+
public function setAttributes(array $attributes = [])
24+
{
25+
$this->attributes = $attributes;
26+
27+
return $this;
28+
}
29+
30+
public function getAttributes()
31+
{
32+
return $this->attributes;
33+
}
34+
2035
public function offsetExists(mixed $offset): bool
2136
{
2237
return Arr::has($this->attributes, $offset);
@@ -54,6 +69,6 @@ public function __get(string $attribute): mixed
5469

5570
public function toArray()
5671
{
57-
return $this->attributes;
72+
return $this->getAttributes();
5873
}
5974
}

0 commit comments

Comments
 (0)