Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Allow passing an array to resource::collection() #30800

Merged
merged 1 commit into from
Dec 11, 2019
Merged

[6.x] Allow passing an array to resource::collection() #30800

merged 1 commit into from
Dec 11, 2019

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Dec 10, 2019

This PR is similar to #25213. I'm trying to use a resource for an array of "normal" classes/objects:

public function index()
{
    /** @var SomeClass[] $array */
    $array = $this->getClasses();

    return SomeResource::collection($array);
}

This currently doesn't work, and throws the following exception: Call to a member function first() on array at /Illuminate/Http/Resources/CollectsResources.php:24.

For now, I'm wrapping the array in a collection, and then passing it to the resource:

return SomeResource::collection(collect($array));

With this PR, I can just pass the array directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants