From 1fc5969f299af51eeaa05c9565aabfc27e6f4c07 Mon Sep 17 00:00:00 2001 From: fokosun Date: Tue, 19 Sep 2023 14:40:41 -0400 Subject: [PATCH] fix keywords endpoint, writes to a file --- app/Http/Controllers/Files/keywords.txt | 1 + app/Http/Controllers/SearchController.php | 16 ++++++++++++++++ composer.json | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Files/keywords.txt diff --git a/app/Http/Controllers/Files/keywords.txt b/app/Http/Controllers/Files/keywords.txt new file mode 100644 index 00000000..225d9eb4 --- /dev/null +++ b/app/Http/Controllers/Files/keywords.txt @@ -0,0 +1 @@ +{"city":"Toronto","country":"CA","ip":"99.225.78.10","keyword":"beans"} \ No newline at end of file diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 6ab22e2b..b62cacb3 100755 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -172,4 +172,20 @@ private function jsonResponse(Collection $collection) 'response' => $collection, ]); } + + public function writeToCsv(Request $request) + { + $data = $request->only(['city', 'country', 'ip', 'keyword', 'loc', 'timezone']); + $filePath = __DIR__ . '/Files/keywords.txt'; + $contents = file_get_contents($filePath); + + if ($contents == "") { + $data = json_encode($data); + } else { + $originalContents = json_decode($contents, true); + $data = json_encode([$data, $originalContents]); + } + + file_put_contents($filePath, $data); + } } diff --git a/composer.json b/composer.json index ccc391d5..076a1011 100755 --- a/composer.json +++ b/composer.json @@ -55,7 +55,8 @@ "database/seeders" ], "files": [ - "app/Http/helpers.php" + "app/Http/helpers.php", + "app/Http/Controllers/Files/keywords.txt" ] }, "autoload-dev": {