-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Support API Resources #70
Support API Resources #70
Conversation
Hmm, I thought this worked already? I've used API resources. They automatically get converted to JSON, so this shouldn't be needed. Plus, we also added I'll tag that now. Can you try this again, on the latest version? I suspect it will work without any changes needed to the library. |
forgive my poor English 😄 |
And I have test many usage.Here is some examples:
And the Notice that if you want to append other data to a collection.
defined in a resource and use |
This is true, and a super annoying thing with Laravel resources. When calling It's debatable whether Inertia should cast this for the user though, since some people might expect to only get the data when passing down an Eloquent resource collection. I personally would be very happy with this change, but I don't know what others are doing with resources; it might be to opinionated. |
55c92bc
to
3c803cb
Compare
3c803cb
to
7822ef4
Compare
This PR will save time and a Collection class if you go the Laravel resource route. In our team the resource is a good api for transforming data, I like it a lot. |
While I would agree that it's "opinionated," I think this fits with Laravel's "convention over configuration" approach. And since this is a package for Laravel I think this would be really great to include, especially since it's such a simple change. It seems really natural to me to use API Resources when passing data to the components since this "hybrid" approach is trying to take the best of both worlds. Leveraging API Resources with Inertia would 💯, thanks for taking the time for this |
@@ -48,6 +49,10 @@ public function getVersion() | |||
|
|||
public function render($component, $props = []) | |||
{ | |||
if ($props instanceof JsonResource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in my case, I would be passing an array of props, with some being an instance of JsonResource
.
It would need to iterate each of the props to resolve them as well. It may be worth rethinking this a little...
@reinink Any updates on this? I need the resource meta, so I'd love to see one of the solutions merged.. |
So, I've added support for "Responsable" props: 2b966ac As you can see, my approach here is almost identical to this PR. However, instead of checking for a I've tested this with both single resource responses and collection resource responses, and it works great. Thanks, either way, for submitting this PR @winter-ice. 👍 |
resolve #27 #28
Use like:
or