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

[4.0] Support of nested relations when viewing #40

Open
tabuna opened this issue Apr 25, 2021 · 0 comments
Open

[4.0] Support of nested relations when viewing #40

tabuna opened this issue Apr 25, 2021 · 0 comments

Comments

@tabuna
Copy link
Member

tabuna commented Apr 25, 2021

It would be great to add a display of nested resources when browsing, for example:

image

In this regard, I propose to add a new method to the resource class responsible for this:

public function relations(): array
{
    return [
        Single('user', UserResource::class),
        Many('comments', CommentResource::class),
    ];
}

Where the first argument will be the name of the communication method in the model, that is:

class Post extends Model
{
    // ...

    public function user()
    {
        return $this->belongsTo(User::class, 'author');
    }

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

And the second will be the name of the class in which you want to display the resulting models.

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

No branches or pull requests

1 participant