Skip to content

Commit 0993b36

Browse files
committed
Improve data wrapper vol 2
1 parent 0ed7b88 commit 0993b36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Lodash/Http/Resources/ErrorResource.php

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Longman\LaravelLodash\Http\Resources;
66

7+
use function array_merge;
8+
79
class ErrorResource extends JsonResource
810
{
911
public static $wrap = null;
@@ -14,4 +16,20 @@ public function __construct(array $resource)
1416

1517
$this->setDataWrapper('');
1618
}
19+
20+
public function toArray($request): array
21+
{
22+
/**
23+
* Merge additional info and unset it, due to it causing
24+
* `errors` array to be wrapped in unnecessary `data` property
25+
*/
26+
$result = array_merge(
27+
$this->resource,
28+
$this->additional ?? [],
29+
);
30+
31+
$this->additional([]);
32+
33+
return $result;
34+
}
1735
}

0 commit comments

Comments
 (0)