Customize attach search query

Hi, I'm attempting to override the search query on an Attach Action, but can't seem to find if and how I can do that. The idea here is that I'd like the search to apply the following SQL: WHERE ´column´ LIKE 'search%' Seeing as I don't want the attach dropdown to show items that don't start with the search query. Is this possible somehow? Thanks!
Solution:
Else build your own attach action.
Jump to solution
11 Replies
Flippulus
Flippulus4w ago
I already use that method for something else, but can I override the search logic itself in that method? Can I access the $search query in the method? Thanks for the help!
toeknee
toeknee4w ago
Depends where 'search' query is in your mind.
Flippulus
Flippulus4w ago
As in what I fill into the select, sorry if I don't make sense 🙈 See screenshot:
No description
Flippulus
Flippulus4w ago
The search only applies to the numbers in front of the text (I set it like that using "recordSelectSearchColumns"). But I'd like, when I search for '1.1' it would only show me results that start with '1.1' and not results like for example '12.1.1'
Flippulus
Flippulus4w ago
Hmmm, my PHPStorm tells me this method is unknown on the Attach Action 🤔
No description
Flippulus
Flippulus4w ago
It would be great if it'd be possible that way ofcourse!
toeknee
toeknee4w ago
I said to try passing search into the closure, not call a new function,
AttachAction::make()
->recordSelectOptionsQuery(fn (Builder $query, $search) => dd($search))
AttachAction::make()
->recordSelectOptionsQuery(fn (Builder $query, $search) => dd($search))
Might not work, I haven't checked but worth a try.
Solution
toeknee
toeknee4w ago
Else build your own attach action.
Flippulus
Flippulus4w ago
Oh apologies. I tried that and sadly it could not resolve $search Alright, I'll take a look into building my own attach action, thanks for the assistance 👍