-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Unable to use query builder results in Api Resource class #31703
Comments
Seems duplicate of #29916? |
Resources only work with eloquent models. |
Restores php 7.4 compatibility for paginator resources that receives objects (for example from the query builder) instead of models. Fixes laravel#31703 and laravel#29916
@driesvints If resource work only with eloquent model, then why passing a this works
this doesn't
A solution would be to create a ModelResourceCollection and extend de framework's behaviour but this doesn't sound like future proof to me. Would such a class be helpful? |
Description:
When i use the result of a query builder and i put it in a API Resource class i get an error that the stdClass object cannot be used as an array. When i die dump the resource, it wil give me a valid resource back, but it generates an error when i want to return the resource in my controller
I've tested it with the mysql and pgsql driver, both have the same issue.
Steps To Reproduce:
Create a controller with this in it:
Put this in the
toArray
method of theUserResource
:The text was updated successfully, but these errors were encountered: