diff --git a/src/LaravelServerAnalytics.php b/src/LaravelServerAnalytics.php index 89f6eb7..ff14034 100644 --- a/src/LaravelServerAnalytics.php +++ b/src/LaravelServerAnalytics.php @@ -244,6 +244,7 @@ public function logRequest(Request $request, Response $response): Analytics $analytics = Analytics::create([ 'user_id' => $userId, 'method' => $this->requestDetails->getMethod(), + 'host' => $this->requestDetails->getHost(), 'path' => $this->requestDetails->getPath(), 'status_code' => $this->requestDetails->getStatusCode(), 'user_agent' => $this->requestDetails->getUserAgent(), diff --git a/src/Models/Analytics.php b/src/Models/Analytics.php index 2e2bc4d..3596ab2 100644 --- a/src/Models/Analytics.php +++ b/src/Models/Analytics.php @@ -14,7 +14,7 @@ public function getTable() } protected $fillable = [ - 'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address' + 'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address', 'host' ]; protected $casts = [ diff --git a/src/RequestDetails.php b/src/RequestDetails.php index 5b40999..03f9bec 100644 --- a/src/RequestDetails.php +++ b/src/RequestDetails.php @@ -33,6 +33,16 @@ public function getMethod(): string return strtoupper($this->request->getMethod()); } + /** + * Returns the host of the request. + * + * @return string + */ + public function getHost(): string + { + return $this->request->getHost(); + } + /** * Returns the path of the request. * diff --git a/src/database/migrations/2022_05_17_000000_add_host_to_analytics_table.php b/src/database/migrations/2022_05_17_000000_add_host_to_analytics_table.php new file mode 100644 index 0000000..2e44cf5 --- /dev/null +++ b/src/database/migrations/2022_05_17_000000_add_host_to_analytics_table.php @@ -0,0 +1,25 @@ +string('host')->nullable()->before('path'); + }); + } + + public function down() + { + Schema::table(ServerAnalytics::getAnalyticsDataTable(), function (Blueprint $table) { + $table->dropColumn('host'); + }); + } +}