66
77use  Illuminate \Database \Eloquent \Builder ;
88use  Illuminate \Database \Eloquent \Model ;
9+ use  Illuminate \Database \Query \Expression ;
910use  Illuminate \Support \Collection ;
1011use  Illuminate \Support \Str ;
1112
1213readonly  class  ModelToSearchThrough
1314{
1415    /** 
1516     * @param  Builder<Model>  $builder  Builder to search through 
16-      * @param  Collection<int, string>  $columns  The columns to search through 
17+      * @param  Collection<int, string|Expression >  $columns  The columns to search through 
1718     * @param  string  $orderByColumn  Order column 
1819     * @param  int  $key  Unique key of this instance 
1920     * @param  bool  $fullText  Full-text search 
@@ -59,7 +60,7 @@ public function getFreshBuilder(): Builder
5960    /** 
6061     * Get a collection with all columns or relations to search through. 
6162     * 
62-      * @return Collection<int, string> 
63+      * @return Collection<int, string|Expression > 
6364     */ 
6465    public  function  getColumns (): Collection 
6566    {
@@ -69,7 +70,7 @@ public function getColumns(): Collection
6970    /** 
7071     * Create a new instance with different columns to search through. 
7172     * 
72-      * @param  Collection<int, string>  $columns 
73+      * @param  Collection<int, string|Expression >  $columns 
7374     */ 
7475    public  function  setColumns (Collection $ columnsself 
7576    {
@@ -88,11 +89,11 @@ public function setColumns(Collection $columns): self
8889     * Get a collection with all qualified columns 
8990     * to search through. 
9091     * 
91-      * @return Collection<int, string> 
92+      * @return Collection<int, string|Expression > 
9293     */ 
9394    public  function  getQualifiedColumns (): Collection 
9495    {
95-         return  $ this columns ->map (fn  ( string   $ column =>  $ this qualifyColumn ($ column
96+         return  $ this columns ->map (fn ( $ column:  \ Illuminate \ Database \ Query \ Expression | string  =>  $ column   instanceof  Expression ?  $ column  :  $ this qualifyColumn ($ column
9697    }
9798
9899    /** 
@@ -125,6 +126,14 @@ public function qualifyColumn(string $column): string
125126        return  $ this getModel ()->qualifyColumn ($ column
126127    }
127128
129+     /** 
130+      * Check if a column is a raw expression. 
131+      */ 
132+     public  function  isRawExpression (mixed  $ columnbool 
133+     {
134+         return  $ columninstanceof  Expression;
135+     }
136+ 
128137    /** 
129138     * Get the qualified key name. 
130139     */ 
0 commit comments