You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using your repo as a guide to make an API and I have a doubt. Hope you can help me.
When you have a related entity. For example, if the Book Author is another Author model. What's the best approach?
Now what I'm doing is in the BookResource, use 'author' => new AuthorResource( $this->author ). It works, and it shows the information, but I suposse I'll have problems with recursivity easily.
Is there any feature like a "link"? I mean, in author show a link to the resource to get the author data like "API URL/authors/12".
Many thanks
The text was updated successfully, but these errors were encountered:
If you have to relate entities it is certainly better to use laravel resources which are a great thing, since when I use them I have been able to do better relationships between bees.
While for the "link" functions you should do a collection of resources something like:
class BookCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection,
'links' => [
'self' => 'link-value',
],
];
}
}
Hello,
I'm using your repo as a guide to make an API and I have a doubt. Hope you can help me.
When you have a related entity. For example, if the Book Author is another Author model. What's the best approach?
Now what I'm doing is in the BookResource, use
'author' => new AuthorResource( $this->author )
. It works, and it shows the information, but I suposse I'll have problems with recursivity easily.Is there any feature like a "link"? I mean, in author show a link to the resource to get the author data like "API URL/authors/12".
Many thanks
The text was updated successfully, but these errors were encountered: