File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ You can chain methods to the `visit` method. Here are a list of the available me
80
80
| METHOD | SYNTAX | DESCRIPTION | EXAMPLE |
81
81
| ----------- | ----------- | ----------- | ----------- |
82
82
| ` withIp() ` | string ` $ip = null ` | Set an Ip address (default ` request()->ip() ` ) | ` $post->visit()->withIp() ` |
83
+ | ` withSession() ` | string ` $session = null ` | Set an Session ID (default ` session()->getId() ` ) | ` $post->visit()->withSession() ` |
83
84
| ` withData() ` | array ` $data ` | Set custom data | ` $post->visit()->withData(['region' => 'USA']) ` |
84
85
| ` withUser() ` | Model ` $user = null ` | Set a user model (default ` auth()->user() ` ) | ` $user->visit()->withUser() ` |
85
86
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 ' ] = $ session ?? 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 ' => 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