File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,19 @@ public function withIP(string $ip = null): self
47
47
return $ this ;
48
48
}
49
49
50
+ /**
51
+ * Set Session attribute
52
+ *
53
+ * @param string $session
54
+ * @return $this
55
+ */
56
+ public function withSession (string $ session = null ): self
57
+ {
58
+ $ this ->attributes ['session ' ] = $ ip ?? request ()->session ()->getId ();
59
+
60
+ return $ this ;
61
+ }
62
+
50
63
/**
51
64
* Set Custom Data attribute
52
65
*
Original file line number Diff line number Diff line change 44
44
]);
45
45
});
46
46
47
+ it ('creates a visit with the default session id ' , function () {
48
+ $ post = Post::factory ()->create ();
49
+
50
+ $ post ->visit ()->withSession ();
51
+
52
+ expect ($ post ->visits ->first ()->data )
53
+ ->toMatchArray ([
54
+ 'session ' => request ()->session ()->getId (),
55
+ ]);
56
+ });
57
+
58
+ it ('creates a visit with the given session id ' , function () {
59
+ $ post = Post::factory ()->create ();
60
+
61
+ $ post ->visit ()->withSession ('RSXXvRiviUu2wO3RTmLESztufikmuV2F8KSugDzu ' );
62
+
63
+ expect ($ post ->visits ->first ()->data )
64
+ ->toMatchArray ([
65
+ 'session ' => 'RSXXvRiviUu2wO3RTmLESztufikmuV2F8KSugDzu ' ,
66
+ ]);
67
+ });
68
+
47
69
it ('gets the correct ip when creating a visit ' , function () {
48
70
$ post = Post::factory ()->create ();
49
71
You can’t perform that action at this time.
0 commit comments