瀏覽代碼

Fix null resource error on @apiResourceCollection

ccec1t91077 2 年之前
父節點
當前提交
d28bff50d7
共有 1 個文件被更改,包括 3 次插入1 次删除
  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) {