This commit is contained in:
nfangxu 2020-06-23 14:44:40 +08:00
parent 750dd8e28f
commit de4f7dfbc0
3 changed files with 11 additions and 3 deletions

View File

@ -41,3 +41,5 @@ parameters:
- '#Method Hyperf\\Utils\\Serializer\\ScalarNormalizer::denormalize\(\) should return array\|object but returns#'
- '#Function get_debug_type invoked with 1 parameter, 0 required#'
- '#gc_status not found#'
- '#Call to an undefined method Hyperf\\Utils\\HigherOrderCollectionProxy::toMessage().#'
- '#Access to an undefined property Hyperf\\Resource\\Json\\JsonResource::\$preserveKeys.#'

View File

@ -97,7 +97,7 @@ trait ConditionallyLoadsAttributes
if (($value instanceof PotentiallyMissing && $value->isMissing()) ||
($value instanceof self &&
$value->resource instanceof PotentiallyMissing &&
$value->isMissing())) {
$value->resource->isMissing())) {
unset($data[$key]);
} else {
$numericKeys = $numericKeys && is_numeric($key);

View File

@ -9,6 +9,7 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Resource\Json;
use Countable;
@ -62,7 +63,9 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr
*/
public function toArray(): array
{
return $this->collection->map->toArray()->all();
/** @var Collection $collection */
$collection = $this->collection->map->toArray();
return $collection->all();
}
public function toResponse()
@ -76,6 +79,9 @@ class ResourceCollection extends JsonResource implements Countable, IteratorAggr
public function toMessage()
{
return $this->collection->map->toMessage()->all();
/** @var Collection $collection */
$collection = $this->collection->map->toMessage();
return $collection->all();
}
}