66use Statamic \Contracts \Query \Builder ;
77use Statamic \Facades \User ;
88use Statamic \Fields \Blueprint ;
9+ use Statamic \Search \QueryBuilder as SearchQueryBuilder ;
910
1011trait QueriesAuthorEntries
1112{
@@ -21,10 +22,20 @@ protected function queryAuthorEntries(Builder $query, Collection $collection): v
2122 // Exclude entries from other collections (for entries fieldtypes with multiple collections)
2223 ->whereNotIn ('collectionHandle ' , [$ collection ->handle ()])
2324 // Include entries with blueprints where the current user is the author
24- ->orWhere (fn ($ query ) => $ query
25- ->whereIn ('blueprint ' , $ blueprintsWithAuthor )
26- ->whereHas ('author ' , fn ($ query ) => $ query ->where ('id ' , User::current ()->id ()))
27- )
25+ ->orWhere (function ($ query ) use ($ collection , $ blueprintsWithAuthor ) {
26+ $ query ->whereIn ('blueprint ' , $ blueprintsWithAuthor );
27+
28+ if ($ query instanceof SearchQueryBuilder) {
29+ $ ids = $ collection ->queryEntries ()
30+ ->whereHas ('author ' , fn ($ query ) => $ query ->where ('id ' , User::current ()->id ()))
31+ ->pluck ('id ' )
32+ ->all ();
33+
34+ return $ query ->whereIn ('id ' , $ ids );
35+ }
36+
37+ return $ query ->whereHas ('author ' , fn ($ query ) => $ query ->where ('id ' , User::current ()->id ()));
38+ })
2839 // Include entries with blueprints that don't have an author
2940 ->orWhereIn ('blueprint ' , $ this ->blueprintsWithoutAuthor ($ collection ))
3041 );
0 commit comments