Global Search
First, a quick video demo of the module.

How does it work?

After installing the module, you can enable any individual field in any CRUD to be "searchable":
And then, in the generated panel, in top-left corner, you will see a search field, which, after you type in at least 3 characters, will look for all records in all CRUDs/Fields you specified:

Customization

If you want to customize the behavior of Global Search, it's all in the generated file app/Http/Controllers/Admin/GlobalSearchController.php, here's the main method:
1
public function search(Request $request)
2
{
3
$search = $request->input('search');
4
​
5
if ($search === null || !isset($search['term'])) {
6
abort(400);
7
}
8
​
9
$term = $search['term'];
10
$searchableData = [];
11
​
12
foreach ($this->models as $model => $translation) {
13
$modelClass = 'App\\' . $model;
14
$query = $modelClass::query();
15
​
16
$fields = $modelClass::$searchable;
17
​
18
foreach ($fields as $field) {
19
$query->orWhere($field, 'LIKE', '%' . $term . '%');
20
}
21
​
22
$results = $query->take(10)
23
->get();
24
​
25
foreach ($results as $result) {
26
$parsedData = $result->only($fields);
27
$parsedData['model'] = trans($translation);
28
$parsedData['fields'] = $fields;
29
$formattedFields = [];
30
​
31
foreach ($fields as $field) {
32
$formattedFields[$field] = Str::title(str_replace('_', ' ', $field));
33
}
34
​
35
$parsedData['fields_formated'] = $formattedFields;
36
​
37
$parsedData['url'] = url('/admin/' . Str::plural(Str::snake($model, '-')) . '/' . $result->id . '/edit');
38
​
39
$searchableData[] = $parsedData;
40
}
41
}
42
​
43
return response()->json(['results' => $searchableData]);
44
}
Copied!
So if, for example, you want the default click to lead to SHOW method instead of default EDIT, you need to change this line:
1
$parsedData['url'] = url('/admin/' . Str::plural(Str::snake($model, '-')) . '/' . $result->id . '/edit');
Copied!
​
Last modified 1yr ago