Skip to content

Commit bed0be2

Browse files
committed
fix: Prevent duplicate search history entries for the same user and search term.
1 parent 5d9f0e2 commit bed0be2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

app/Http/Controllers/User/SearchController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ public function search($query,$userId){
3333
"search_term" => $query,
3434
]);
3535
if($userId!=0){
36-
37-
$hystory=new History;
38-
$hystory->user_id=$userId;
39-
$hystory->search_term=$query;
40-
$hystory->save();
36+
$history=History::where('user_id',$userId)->where('search_term',$query)->first();
37+
if(isset($history)){
38+
return;
39+
}else{
40+
$hystory=new History;
41+
$hystory->user_id=$userId;
42+
$hystory->search_term=$query;
43+
$hystory->save();
44+
}
4145
}
4246

4347
return response()->json([

0 commit comments

Comments
 (0)