Global Search

By default, Twill's global search input is always available in the dashboard and behind the top-right search icon on other Twill's screens. By default, the search input performs a LIKE query on the title attribute only. If you like, you can specify a custom list of attributes to search for in each dashboard enabled module:

1return [
2 'dashboard' => [
3 'modules' => [
4 'projects' => [
5 'name' => 'projects',
6 'routePrefix' => 'work',
7 'count' => true,
8 'create' => true,
9 'activity' => true,
10 'draft' => true,
11 'search' => true,
12 'search_fields' => ['name', 'description']
13 ],
14 ...
15 ],
16 ...
17 ],
18 ...
19];

You can also customize the endpoint to handle search queries yourself:

1return [
2 'dashboard' => [
3 ...,
4 'search_endpoint' => 'your.custom.search.endpoint.route.name',
5 ],
6 ...
7];

You will need to return a collection of values, like in the following example:

1return $searchResults->map(function ($item) use ($module) {
2 try {
3 $author = $item->revisions()->latest()->first()->user->name ?? 'Admin';
4 } catch (\Exception $e) {
5 $author = 'Admin';
6 }
7 
8 return [
9 'id' => $item->id,
10 'href' => moduleRoute($moduleName['name'], $moduleName['routePrefix'], 'edit', $item->id),
11 'thumbnail' => $item->defaultCmsImage(['w' => 100, 'h' => 100]),
12 'published' => $item->published,
13 'activity' => 'Last edited',
14 'date' => $item->updated_at->toIso8601String(),
15 'title' => $item->title,
16 'author' => $author,
17 'type' => Str::singular($module['name']),
18 ];
19})->values();