+ $sort = setting()->getForCurrentUser('shelf_books_sort', 'default');
+ $order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc');
+
+ $sortedVisibleShelfBooks = $shelf->visibleBooks()->get()
+ ->sortBy($sort === 'default' ? 'pivot.order' : $sort, SORT_REGULAR, $order === 'desc')
+ ->values()
+ ->all();
+
+ View::incrementFor($shelf);