-
Notifications
You must be signed in to change notification settings - Fork 462
fix scout search with soft deleted resource #2305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Changes from all commits
9eafd14
2bda91e
22c0e6e
f7d3e67
53a0155
1fe6e94
7680d36
3fcb555
27346f6
82a64e0
e040c80
a372d0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,21 +32,22 @@ protected function applySearchToTableQuery(Builder $query): Builder | |||||||||||||||
| $scoutEnabled && | ||||||||||||||||
| $isScoutSearchable | ||||||||||||||||
| ) { | ||||||||||||||||
| $ids = collect(static::getModel()::search($search)->take(100)->keys())->map( | ||||||||||||||||
| fn ($result) => str_replace(static::getModel().'::', '', $result) | ||||||||||||||||
| ); | ||||||||||||||||
| $trashedFilter = collect($this->getTable()->getFilters()) | ||||||||||||||||
| ->firstWhere(fn ($filter) => $filter instanceof \Filament\Tables\Filters\TrashedFilter); | ||||||||||||||||
|
|
||||||||||||||||
| $placeholders = implode(',', array_fill(0, count($ids), '?')); | ||||||||||||||||
| $scoutQuery = static::getModel()::search($search); | ||||||||||||||||
|
|
||||||||||||||||
| $query->whereIn( | ||||||||||||||||
| 'id', | ||||||||||||||||
| $ids | ||||||||||||||||
| ); | ||||||||||||||||
| if (filled($state = $trashedFilter?->getState()['value'] ?? null)) { | ||||||||||||||||
| $state ? $scoutQuery->withTrashed() : $scoutQuery->onlyTrashed(); | ||||||||||||||||
|
Comment on lines
+40
to
+41
|
||||||||||||||||
| if (filled($state = $trashedFilter?->getState()['value'] ?? null)) { | |
| $state ? $scoutQuery->withTrashed() : $scoutQuery->onlyTrashed(); | |
| $state = $trashedFilter?->getState()['value'] ?? null; | |
| if ($state === 'with') { | |
| $scoutQuery->withTrashed(); | |
| } elseif ($state === 'only') { | |
| $scoutQuery->onlyTrashed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bot is wrong, just like previous coderabbit review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
TrashedFilterclass should be imported at the top of the file rather than using the fully qualified class name inline. This improves code readability and follows PHP best practices.