Replies: 1 comment 3 replies
-
Can someone open a PR? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, Laravel models provide the
toResource
andtoResourceCollection
methods to transform a model into a JSON resource.This is very convenient since there is no need to manually pass the resource class, as long as the resource name follows the convention:
<ModelName>Resource
.Problem:
In my project, I couldn’t follow the naming convention for resources.
As a result, I need to write calls like this everywhere:
This becomes repetitive and less clean.
Proposed Solution:
It would be great to introduce an attribute that allows developers to define the resource class directly on the model. For example:
With this attribute in place, calls to
toResource()
andtoResourceCollection()
could automatically resolve to the specified resource class, without the need to pass it explicitly every time.Benefits:
toResource
.Beta Was this translation helpful? Give feedback.
All reactions