66use BookStack \Entities \Models \BookChild ;
77use BookStack \Entities \Models \Chapter ;
88use BookStack \Entities \Models \Deletion ;
9+ use BookStack \Entities \Models \Page ;
910use BookStack \Entities \Repos \DeletionRepo ;
1011use BookStack \Http \ApiController ;
11- use Closure ;
12- use Illuminate \Database \Eloquent \Builder ;
12+ use Illuminate \Database \Eloquent \Relations \HasMany ;
1313
1414class RecycleBinApiController extends ApiController
1515{
@@ -40,7 +40,7 @@ public function list()
4040 'updated_at ' ,
4141 'deletable_type ' ,
4242 'deletable_id ' ,
43- ], [Closure:: fromCallable ([ $ this , ' listFormatter ' ] )]);
43+ ], [$ this -> listFormatter (... )]);
4444 }
4545
4646 /**
@@ -72,7 +72,6 @@ public function destroy(DeletionRepo $deletionRepo, string $deletionId)
7272 protected function listFormatter (Deletion $ deletion )
7373 {
7474 $ deletable = $ deletion ->deletable ;
75- $ withTrashedQuery = fn (Builder $ query ) => $ query ->withTrashed ();
7675
7776 if ($ deletable instanceof BookChild) {
7877 $ parent = $ deletable ->getParent ();
@@ -81,11 +80,19 @@ protected function listFormatter(Deletion $deletion)
8180 }
8281
8382 if ($ deletable instanceof Book || $ deletable instanceof Chapter) {
84- $ countsToLoad = ['pages ' => $ withTrashedQuery ];
83+ $ countsToLoad = ['pages ' => static :: withTrashedQuery (...) ];
8584 if ($ deletable instanceof Book) {
86- $ countsToLoad ['chapters ' ] = $ withTrashedQuery ;
85+ $ countsToLoad ['chapters ' ] = static :: withTrashedQuery (...) ;
8786 }
8887 $ deletable ->loadCount ($ countsToLoad );
8988 }
9089 }
90+
91+ /**
92+ * @param HasMany<Chapter|Page, Book|Chapter> $query
93+ */
94+ protected static function withTrashedQuery (HasMany $ query ): void
95+ {
96+ $ query ->withTrashed ();
97+ }
9198}
0 commit comments