File tree Expand file tree Collapse file tree 2 files changed +20
-15
lines changed Expand file tree Collapse file tree 2 files changed +20
-15
lines changed Original file line number Diff line number Diff line change @@ -110,20 +110,25 @@ protected function shouldBeLoggedAgain(Visit $visit): bool
110110
111111 public function __destruct ()
112112 {
113- if (! $ this ->isCrawler ) {
114- $ visit = $ this ->model
115- ->visits ()
116- ->latest ()
117- ->firstOrCreate ($ this ->buildJsonColumns (), [
118- 'data ' => $ this ->attributes ,
119- ]);
120-
121- $ visit ->when (
122- $ this ->shouldBeLoggedAgain ($ visit ),
123- function () use ($ visit ) {
124- $ visit ->replicate ()->save ();
125- }
126- );
113+ // if the current request is a crawler,
114+ // we don't need to log the visit
115+ // because it's not a real visitor
116+ if ($ this ->isCrawler ) {
117+ return null ;
127118 }
119+
120+ $ visit = $ this ->model
121+ ->visits ()
122+ ->latest ()
123+ ->firstOrCreate ($ this ->buildJsonColumns (), [
124+ 'data ' => $ this ->attributes ,
125+ ]);
126+
127+ $ visit ->when (
128+ $ this ->shouldBeLoggedAgain ($ visit ),
129+ function () use ($ visit ) {
130+ $ visit ->replicate ()->save ();
131+ }
132+ );
128133 }
129134}
Original file line number Diff line number Diff line change 225225 request ()->headers ->set ('User-Agent ' , 'Googlebot ' );
226226 $ post ->visit ();
227227
228- expect ($ post ->visits ->first ())->toBe (null );
228+ expect ($ post ->visits ->count ())->toBe (0 );
229229});
You can’t perform that action at this time.
0 commit comments