77use Illuminate \Pagination \LengthAwarePaginator ;
88use Illuminate \Support \Collection ;
99use Illuminate \Support \Facades \DB ;
10+ use Illuminate \Support \Str ;
1011use Statikbe \FilamentFlexibleContentBlockPages \Facades \FilamentFlexibleContentBlockPages ;
1112use Statikbe \FilamentFlexibleContentBlockPages \Models \Tag ;
1213
@@ -30,7 +31,7 @@ public function getTaggedContent(Tag $tag, ?int $perPage = null): LengthAwarePag
3031 $ groupedIds = collect ($ unionResults ->items ())->groupBy ('model_class ' );
3132
3233 // Step 3: Load actual models in batches
33- $ models = $ this ->hydrateModels ($ groupedIds, $ tag );
34+ $ models = $ this ->hydrateModels ($ groupedIds );
3435
3536 // Return as paginator with actual models
3637 return new LengthAwarePaginator (
@@ -55,12 +56,13 @@ private function getUnionQueryResults(Tag $tag, int $perPage): LengthAwarePagina
5556
5657 foreach ($ enabledModels as $ modelClass ) {
5758 /** @var class-string $modelClass */
59+ $ escapedModelClass = Str::replace ('\\' , '\\\\' , $ modelClass );
5860 $ query = $ modelClass ::withAnyTagsOfAnyType ([$ tag ->name ])
5961 ->select ([
6062 'id ' ,
6163 'publishing_begins_at ' ,
6264 'created_at ' , // fallback for sorting
63- DB ::raw ("' {$ modelClass }' as model_class " ),
65+ DB ::raw ("' {$ escapedModelClass }' as model_class " ),
6466 ]);
6567
6668 // Add published scope if available
@@ -91,7 +93,7 @@ private function getUnionQueryResults(Tag $tag, int $perPage): LengthAwarePagina
9193 /**
9294 * Hydrate actual model instances from the union query results.
9395 */
94- private function hydrateModels (Collection $ groupedIds, Tag $ tag ): Collection
96+ private function hydrateModels (Collection $ groupedIds ): Collection
9597 {
9698 $ models = collect ();
9799
@@ -156,7 +158,7 @@ public function getContentCounts(Tag $tag): array
156158
157159 foreach ($ enabledModels as $ modelClass ) {
158160 /** @var class-string $modelClass */
159- $ count = $ modelClass ::withAnyTags ([$ tag ->name ])
161+ $ count = $ modelClass ::withAnyTagsOfAnyType ([$ tag ->name ])
160162 ->when (method_exists ($ modelClass , 'scopePublished ' ), function ($ query ) {
161163 return $ query ->published ();
162164 })
0 commit comments