@@ -556,7 +556,9 @@ private function addRelevanceQueryToBuilder($builder, $modelToSearchThrough)
556556 */
557557 protected function makeSelects (ModelToSearchThrough $ currentModel ): array
558558 {
559- $ selects = $ this ->modelsToSearchThrough ->flatMap (function (ModelToSearchThrough $ modelToSearchThrough ) use ($ currentModel ) {
559+ $ grammar = $ this ->getSearchGrammar ();
560+
561+ $ selects = $ this ->modelsToSearchThrough ->flatMap (function (ModelToSearchThrough $ modelToSearchThrough ) use ($ currentModel , $ grammar ) {
560562 $ qualifiedKeyName = $ qualifiedOrderByColumnName = $ modelOrderKey = 'null ' ;
561563
562564 if ($ modelToSearchThrough === $ currentModel ) {
@@ -578,9 +580,9 @@ protected function makeSelects(ModelToSearchThrough $currentModel): array
578580 }
579581
580582 return array_filter ([
581- DB ::raw ("{$ qualifiedKeyName } as {$ modelToSearchThrough ->getModelKey ()}" ),
582- DB ::raw ("{$ qualifiedOrderByColumnName } as {$ modelToSearchThrough ->getModelKey ('order ' )}" ),
583- $ this ->orderByModel ? DB ::raw ("{$ modelOrderKey } as {$ modelToSearchThrough ->getModelKey ('model_order ' )}" ) : null ,
583+ DB ::raw ("{$ qualifiedKeyName } as {$ grammar -> wrap ( $ modelToSearchThrough ->getModelKey () )}" ),
584+ DB ::raw ("{$ qualifiedOrderByColumnName } as {$ grammar -> wrap ( $ modelToSearchThrough ->getModelKey ('order ' ) )}" ),
585+ $ this ->orderByModel ? DB ::raw ("{$ modelOrderKey } as {$ grammar -> wrap ( $ modelToSearchThrough ->getModelKey ('model_order ' ) )}" ) : null ,
584586 ]);
585587 })->all ();
586588
@@ -596,7 +598,9 @@ protected function makeSelects(ModelToSearchThrough $currentModel): array
596598 protected function makeOrderBy (): string
597599 {
598600 $ grammar = $ this ->getSearchGrammar ();
599- $ modelOrderKeys = $ this ->modelsToSearchThrough ->map ->getModelKey ('order ' )->toArray ();
601+ $ modelOrderKeys = $ this ->modelsToSearchThrough ->map (function ($ modelToSearchThrough ) use ($ grammar ) {
602+ return $ grammar ->wrap ($ modelToSearchThrough ->getModelKey ('order ' ));
603+ })->toArray ();
600604
601605 return $ grammar ->coalesce ($ modelOrderKeys );
602606 }
@@ -610,7 +614,9 @@ protected function makeOrderBy(): string
610614 protected function makeOrderByModel (): string
611615 {
612616 $ grammar = $ this ->getSearchGrammar ();
613- $ modelOrderKeys = $ this ->modelsToSearchThrough ->map ->getModelKey ('model_order ' )->toArray ();
617+ $ modelOrderKeys = $ this ->modelsToSearchThrough ->map (function ($ modelToSearchThrough ) use ($ grammar ) {
618+ return $ grammar ->wrap ($ modelToSearchThrough ->getModelKey ('model_order ' ));
619+ })->toArray ();
614620
615621 return $ grammar ->coalesce ($ modelOrderKeys );
616622 }
@@ -742,7 +748,9 @@ protected function applyModelOrdering($query): void
742748 }
743749
744750 $ grammar = $ this ->getSearchGrammar ();
745- $ modelOrderKeys = $ this ->modelsToSearchThrough ->map ->getModelKey ('model_order ' )->toArray ();
751+ $ modelOrderKeys = $ this ->modelsToSearchThrough ->map (function ($ modelToSearchThrough ) use ($ grammar ) {
752+ return $ grammar ->wrap ($ modelToSearchThrough ->getModelKey ('model_order ' ));
753+ })->toArray ();
746754 $ modelCoalesceExpr = $ grammar ->coalesce ($ modelOrderKeys );
747755
748756 $ query ->orderByRaw ($ modelCoalesceExpr . ' ' . $ this ->getOrderDirection ());
@@ -774,7 +782,9 @@ protected function applyStandardOrdering($query): void
774782 }
775783
776784 $ grammar = $ this ->getSearchGrammar ();
777- $ orderKeys = $ this ->modelsToSearchThrough ->map ->getModelKey ('order ' )->toArray ();
785+ $ orderKeys = $ this ->modelsToSearchThrough ->map (function ($ modelToSearchThrough ) use ($ grammar ) {
786+ return $ grammar ->wrap ($ modelToSearchThrough ->getModelKey ('order ' ));
787+ })->toArray ();
778788 $ coalesceExpr = $ grammar ->coalesce ($ orderKeys );
779789
780790 $ query ->orderByRaw ($ coalesceExpr . ' ' . $ this ->getOrderDirection ());
0 commit comments