Skip to content

[Bug]: Support for ResrouceCollection #11

@abdul-alhasany

Description

@abdul-alhasany

What happened?

Does the library support ResourceCollection?

How to reproduce the bug

I have a ResourceCollection similar to this:

<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

/**
 * @mixin \App\Models\ModelName
 */
class ResponseResourceCollection extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return $this->collection->transform(fn($item) => $this->transformItem($item))->toArray();
    }

    protected function transformItem($item): array
    {
        return [
            'id' => $item->id,
        ];
    }
}

When running the php artisan runtype:generate command I get this error:
Attempt to read property "id" on array

I also tried changing the mixin to:

/**
 * @mixin \Illuminate\Database\Eloquent\Collection<\App\Models\ModelName>
 */

but I got this error Undefined property: ReflectionClass::$id

Package Version

0.3.1

PHP Version

8.3.19

Laravel Version

11.0.0

Which operating systems does with happen with?

Windows

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions