Skip to content

Commit 27bca82

Browse files
committed
Ensure only allowed searchable columns are used in DB Query
1 parent 8c1a2c2 commit 27bca82

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/Models/Traits/SearchableTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public function scopeSearch(Builder $query, array $search = [])
3434
return $query;
3535
}
3636

37-
if (!array_intersect(array_keys($search), $this->searchable)) {
37+
$allowed_search = array_intersect_key($search, array_flip($this->searchable));
38+
if (! $allowed_search) {
3839
return $query;
3940
}
4041

41-
return $query->where($search);
42+
return $query->where($allowed_search);
4243
}
4344
}

0 commit comments

Comments
 (0)