Replies: 1 comment 1 reply
-
Hi @GregaUNK Thanks for the suggestion; I will discuss the logic you described with the team.
For now, it can be achieved by modifying the query in your controller method public function fetchArticle()
{
return $this->fetch([
'model' => \App\Models\Article::class,
'query' => function ($model) {
$search = request()->input('q') ?? false;
if ($search) {
return $model->where('title', 'LIKE', '%' . $search . '%') // your custom query
->orderByRaw('title LIKE ? DESC', [$search . '%'])
->orderBy('title', 'ASC');
} else {
return $model;
}
},
'searchable_attributes' => []
]);
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
If you have a table with many entries and you start typing “er” in a select2_from_ajax field, the results are displayed sorted by ID. It would be better to prioritize results that start with “er” (e.g., Erazem) and then show results that contain “er” within the string (e.g., Monero).
I believe this type of search logic would be beneficial to many users.
Let me know what you think about it.
Beta Was this translation helpful? Give feedback.
All reactions