orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
138 stars 34 forks source link

[4.0] Support of nested relations when viewing #40

Open tabuna opened 3 years ago

tabuna commented 3 years ago

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.