File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -22,17 +22,44 @@ function filter($data, Request $req): array {
2222 /** Per Page Limit Query Params */
2323 $ limit ??= 10 ;
2424
25+ /** Search Query Params */
26+ $ search ??= null ;
27+
28+ // Search Column Fetch All Data
29+ if ($ search ):
30+ foreach ($ data as $ item ):
31+ $ isSearch = false ;
32+
33+ foreach (array_values ((array ) $ item ) as $ value ):
34+ $ searchWith = str_contains (strtolower (trim (strip_tags ((string ) $ value ))), strtolower (trim ($ search )));
35+
36+ if ($ searchWith )
37+ $ isSearch = true ;
38+ endforeach ;
39+
40+ if ($ isSearch )
41+ array_push ($ filterData , $ item );
42+
43+ endforeach ;
44+ endif ;
45+
2546 // Selected Column Fetch All Data
2647 if ($ filter ):
2748 $ filter = explode (", " , $ filter );
2849
50+ if ($ search )
51+ $ data = $ filterData ;
52+
53+ $ filterData = [];
54+
2955 foreach ($ data as $ item )
3056 array_push ($ filterData , array_intersect_key ((array ) $ item , array_flip ($ filter )));
3157 endif ;
3258
3359 // According Pagination Fetch All Data
3460 if ($ page ):
35- $ filter && $ data = $ filterData ;
61+ if ($ filter || $ search )
62+ $ data = $ filterData ;
3663 $ filterData = array_slice ($ data , $ page == 1 ? 0 : $ limit * ($ page - 1 ), (int ) $ limit );
3764 endif ;
3865
You can’t perform that action at this time.
0 commit comments