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 {
22
22
/** Per Page Limit Query Params */
23
23
$ limit ??= 10 ;
24
24
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
+
25
46
// Selected Column Fetch All Data
26
47
if ($ filter ):
27
48
$ filter = explode (", " , $ filter );
28
49
50
+ if ($ search )
51
+ $ data = $ filterData ;
52
+
53
+ $ filterData = [];
54
+
29
55
foreach ($ data as $ item )
30
56
array_push ($ filterData , array_intersect_key ((array ) $ item , array_flip ($ filter )));
31
57
endif ;
32
58
33
59
// According Pagination Fetch All Data
34
60
if ($ page ):
35
- $ filter && $ data = $ filterData ;
61
+ if ($ filter || $ search )
62
+ $ data = $ filterData ;
36
63
$ filterData = array_slice ($ data , $ page == 1 ? 0 : $ limit * ($ page - 1 ), (int ) $ limit );
37
64
endif ;
38
65
You can’t perform that action at this time.
0 commit comments