- $shelf = Bookshelf::visible()->with(['tags', 'cover', 'createdBy', 'updatedBy'])->findOrFail($id);
+ $shelf = Bookshelf::visible()->with([
+ 'tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy',
+ 'books' => function (BelongsToMany $query) {
+ $query->scopes('visible')->get(['id', 'name', 'slug']);
+ },
+ ])->findOrFail($id);
+