13
13
14
14
namespace ApiPlatform \Laravel \Eloquent \PropertyAccess ;
15
15
16
- use Illuminate \Database \Eloquent \Relations \ HasMany ;
16
+ use Illuminate \Database \Eloquent \Model ;
17
17
use Symfony \Component \PropertyAccess \PropertyAccess ;
18
18
use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
19
19
use Symfony \Component \PropertyAccess \PropertyPathInterface ;
@@ -36,6 +36,12 @@ public function __construct(
36
36
*/
37
37
public function setValue (object |array &$ objectOrArray , string |PropertyPathInterface $ propertyPath , mixed $ value ): void
38
38
{
39
+ if ($ objectOrArray instanceof Model) {
40
+ $ objectOrArray ->{$ propertyPath } = $ value ;
41
+
42
+ return ;
43
+ }
44
+
39
45
$ this ->inner ->setValue ($ objectOrArray , $ propertyPath , $ value );
40
46
}
41
47
@@ -44,20 +50,22 @@ public function setValue(object|array &$objectOrArray, string|PropertyPathInterf
44
50
*/
45
51
public function getValue (object |array $ objectOrArray , string |PropertyPathInterface $ propertyPath ): mixed
46
52
{
47
- $ value = $ this ->inner ->getValue ($ objectOrArray , $ propertyPath );
48
-
49
- if ($ value instanceof HasMany) {
53
+ if ($ objectOrArray instanceof Model) {
50
54
return $ objectOrArray ->{$ propertyPath };
51
55
}
52
56
53
- return $ value ;
57
+ return $ this -> inner -> getValue ( $ objectOrArray , $ propertyPath ) ;
54
58
}
55
59
56
60
/**
57
61
* @param array<mixed, mixed>|object $objectOrArray
58
62
*/
59
63
public function isWritable (object |array $ objectOrArray , string |PropertyPathInterface $ propertyPath ): bool
60
64
{
65
+ if ($ objectOrArray instanceof Model) {
66
+ return true ;
67
+ }
68
+
61
69
return $ this ->inner ->isWritable ($ objectOrArray , $ propertyPath );
62
70
}
63
71
@@ -66,6 +74,10 @@ public function isWritable(object|array $objectOrArray, string|PropertyPathInter
66
74
*/
67
75
public function isReadable (object |array $ objectOrArray , string |PropertyPathInterface $ propertyPath ): bool
68
76
{
77
+ if ($ objectOrArray instanceof Model) {
78
+ return true ;
79
+ }
80
+
69
81
return $ this ->inner ->isReadable ($ objectOrArray , $ propertyPath );
70
82
}
71
83
}
0 commit comments