@@ -12,13 +12,13 @@ class ExportService
1212 public function exportToCsv (Collection $ data , array $ columns = []): string
1313 {
1414 $ csv = Writer::createFromString ('' );
15-
15+
1616 // Add headers
1717 if (empty ($ columns ) && $ data ->isNotEmpty ()) {
1818 $ columns = array_keys ($ data ->first ()->toArray ());
1919 }
2020 $ csv ->insertOne ($ columns );
21-
21+
2222 // Add data rows
2323 foreach ($ data as $ row ) {
2424 $ csvRow = [];
@@ -27,7 +27,7 @@ public function exportToCsv(Collection $data, array $columns = []): string
2727 }
2828 $ csv ->insertOne ($ csvRow );
2929 }
30-
30+
3131 return $ csv ->toString ();
3232 }
3333
@@ -39,51 +39,51 @@ public function exportToJson(Collection $data): string
3939 public function getAnalyticsData (array $ filters = []): Collection
4040 {
4141 $ query = RequestAnalytics::query ();
42-
42+
4343 if (isset ($ filters ['start_date ' ])) {
4444 $ query ->where ('visited_at ' , '>= ' , $ filters ['start_date ' ]);
4545 }
46-
46+
4747 if (isset ($ filters ['end_date ' ])) {
4848 $ query ->where ('visited_at ' , '<= ' , $ filters ['end_date ' ]);
4949 }
50-
50+
5151 if (isset ($ filters ['path ' ])) {
52- $ query ->where ('path ' , 'like ' , '% ' . $ filters ['path ' ] . '% ' );
52+ $ query ->where ('path ' , 'like ' , '% ' . $ filters ['path ' ]. '% ' );
5353 }
54-
54+
5555 if (isset ($ filters ['country ' ])) {
5656 $ query ->where ('country ' , $ filters ['country ' ]);
5757 }
58-
58+
5959 if (isset ($ filters ['browser ' ])) {
6060 $ query ->where ('browser ' , $ filters ['browser ' ]);
6161 }
62-
62+
6363 if (isset ($ filters ['device ' ])) {
6464 $ query ->where ('device ' , $ filters ['device ' ]);
6565 }
66-
66+
6767 return $ query ->get ();
6868 }
6969
7070 public function downloadCsv (Collection $ data , string $ filename = 'analytics_export.csv ' )
7171 {
7272 $ csv = $ this ->exportToCsv ($ data );
73-
73+
7474 return Response::make ($ csv , 200 , [
7575 'Content-Type ' => 'text/csv ' ,
76- 'Content-Disposition ' => 'attachment; filename=" ' . $ filename . '" ' ,
76+ 'Content-Disposition ' => 'attachment; filename=" ' . $ filename. '" ' ,
7777 ]);
7878 }
7979
8080 public function downloadJson (Collection $ data , string $ filename = 'analytics_export.json ' )
8181 {
8282 $ json = $ this ->exportToJson ($ data );
83-
83+
8484 return Response::make ($ json , 200 , [
8585 'Content-Type ' => 'application/json ' ,
86- 'Content-Disposition ' => 'attachment; filename=" ' . $ filename . '" ' ,
86+ 'Content-Disposition ' => 'attachment; filename=" ' . $ filename. '" ' ,
8787 ]);
8888 }
89- }
89+ }
0 commit comments