Browse Source

Fix null resource error on @apiResourceCollection

ccec1t91077 2 years ago
parent
commit
d28bff50d7
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/Extracting/Shared/ApiResourceResponseTools.php

+ 3 - 1
src/Extracting/Shared/ApiResourceResponseTools.php

@@ -54,7 +54,9 @@ class ApiResourceResponseTools
         array  $paginationStrategy = [], array $additionalData = []
     ): JsonResource
     {
-        $modelInstance = $modelInstantiator();
+        // If the JsonResource is working with empty $resource (such like an empty array), the $modelInstantiator will be null
+        // If $modelInstantiator is null set to an empty array as default
+        $modelInstance = $modelInstantiator() ?? [];
         try {
             $resource = new $apiResourceClass($modelInstance);
         } catch (Exception) {