File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1212class Relationship implements Resourceable
1313{
1414 public function __construct (
15- protected Resourceable $ resource ,
15+ protected $ resource ,
1616 protected iterable |Closure $ links = [],
1717 protected iterable |Closure $ meta = []
1818 ) {
@@ -49,9 +49,13 @@ public function toArray($request, bool $minimal = false): array
4949 ];
5050 }
5151
52- $ included = [];
52+ if (method_exists ($ resource , 'toArray ' )) {
53+ $ datum = $ resource ->toArray ($ request , $ minimal );
54+ } else {
55+ $ datum = collect ($ resource )->toArray ();
56+ }
5357
54- $ datum = $ resource -> toArray ( $ request , $ minimal ) ;
58+ $ included = [] ;
5559
5660 if ($ resource instanceof ResourceCollection) {
5761 foreach ($ datum as $ value ) {
@@ -76,7 +80,7 @@ public function toArray($request, bool $minimal = false): array
7680 return array_filter ([
7781 'data ' => array_filter ($ data ),
7882 'included ' => $ included ,
79- 'with ' => $ resource ->with ($ request )
83+ 'with ' => method_exists ( $ resource, ' with ' ) ? $ resource ->with ($ request ) : null
8084 ]);
8185 }
8286
You can’t perform that action at this time.
0 commit comments