]> BookStack Code Mirror - bookstack/blobdiff - app/Sorting/SortSet.php
Sorting: Added auto sort option to book sort UI
[bookstack] / app / Sorting / SortSet.php
index a73407bfa08e58e8c695701a34b98e12be034849..8cdee1df49c4e24b276616328a94a1dfae7fda05 100644 (file)
@@ -5,6 +5,7 @@ namespace BookStack\Sorting;
 use BookStack\Activity\Models\Loggable;
 use BookStack\Entities\Models\Book;
 use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\HasMany;
 
@@ -48,4 +49,12 @@ class SortSet extends Model implements Loggable
     {
         return $this->hasMany(Book::class);
     }
+
+    public static function allByName(): Collection
+    {
+        return static::query()
+            ->withCount('books')
+            ->orderBy('name', 'asc')
+            ->get();
+    }
 }