Skip to content

Commit 033cbb9

Browse files
committed
fix: Fix tracking referrer field by making it fillable in Analytics model
1 parent b433113 commit 033cbb9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Models/Analytics.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function getTable()
1414
}
1515

1616
protected $fillable = [
17-
'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address', 'host'
17+
'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address', 'referrer', 'host'
1818
];
1919

2020
protected $casts = [
@@ -35,7 +35,7 @@ public function addRelation(Model $entity, ?string $reason = null): AnalyticsRel
3535
]);
3636
$relation->relation()->associate($entity);
3737
$this->relations()->save($relation);
38-
38+
3939
return $relation;
4040
}
4141

tests/AnalyticsTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AnalyticsTest extends TestCase
1414
public function it_tracks_a_request()
1515
{
1616
// When
17-
$this->get('/analytics');
17+
$this->withHeader('referer', 'https://google.com')->get('/analytics');
1818

1919
// Then
2020
$this->assertDatabaseHas(ServerAnalytics::getAnalyticsDataTable(), [
@@ -24,6 +24,7 @@ public function it_tracks_a_request()
2424
'status_code' => '200',
2525
'user_agent' => 'Symfony',
2626
'ip_address' => '127.0.0.1',
27+
'referrer' => 'https://google.com',
2728
'query_params' => json_encode([])
2829
]);
2930
}
@@ -69,7 +70,7 @@ public function it_tracks_authenticated_user_with_request()
6970
{
7071
// Given
7172
$user = factory(User::class)->create();
72-
73+
7374
// When
7475
$this->be($user)->get('/api/analytics');
7576

0 commit comments

Comments
 (0)