File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 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
8080| METHOD | SYNTAX | DESCRIPTION | EXAMPLE |
8181| ----------- | ----------- | ----------- | ----------- |
8282| ` 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() ` |
8384| ` withData() ` | array ` $data ` | Set custom data | ` $post->visit()->withData(['region' => 'USA']) ` |
8485| ` withUser() ` | Model ` $user = null ` | Set a user model (default ` auth()->user() ` ) | ` $user->visit()->withUser() ` |
8586
Original file line number Diff line number Diff line change @@ -47,6 +47,19 @@ public function withIP(string $ip = null): self
4747 return $ this ;
4848 }
4949
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+
5063 /**
5164 * Set Custom Data attribute
5265 *
Original file line number Diff line number Diff line change 4444 ]);
4545});
4646
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+
4769it ('gets the correct ip when creating a visit ' , function () {
4870 $ post = Post::factory ()->create ();
4971
You can’t perform that action at this time.
0 commit comments