Skip to content

Commit

Permalink
Only search browsable fields (#5281)
Browse files Browse the repository at this point in the history
  • Loading branch information
emptynick authored May 1, 2021
1 parent e22d212 commit c819b66
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Http/Controllers/VoyagerBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,9 @@ public function index(Request $request)

$searchNames = [];
if ($dataType->server_side) {
$searchable = SchemaManager::describeTable(app($dataType->model_name)->getTable())->pluck('name')->toArray();
$dataRow = Voyager::model('DataRow')->whereDataTypeId($dataType->id)->get();
foreach ($searchable as $key => $value) {
$field = $dataRow->where('field', $value)->first();
$displayName = ucwords(str_replace('_', ' ', $value));
if ($field !== null) {
$displayName = $field->getTranslatedAttribute('display_name');
}
$searchNames[$value] = $displayName;
}
$searchNames = $dataType->browseRows->mapWithKeys(function ($row) {
return [$row['field'] => $row->getTranslatedAttribute('display_name')];
});
}

$orderBy = $request->get('order_by', $dataType->order_column);
Expand Down Expand Up @@ -100,7 +93,9 @@ public function index(Request $request)
$row->details->model::where($row->details->label, $search_filter, $search_value)->pluck('id')->toArray()
);
} else {
$query->where($searchField, $search_filter, $search_value);
if ($dataType->browseRows->pluck('field')->contains($search->key)) {
$query->where($searchField, $search_filter, $search_value);
}
}
}

Expand Down

0 comments on commit c819b66

Please sign in to comment.