Skip to content

fix scout search with soft deleted resource#2305

Merged
alecritson merged 15 commits intolunarphp:1.xfrom
wychoong:fix/scout-search-with-soft-deleted-resource
Apr 16, 2026
Merged

fix scout search with soft deleted resource#2305
alecritson merged 15 commits intolunarphp:1.xfrom
wychoong:fix/scout-search-with-soft-deleted-resource

Conversation

@wychoong
Copy link
Copy Markdown
Contributor

@wychoong wychoong commented Oct 2, 2025

To use Scout search with soft delete model, as per laravel doc

set the soft_delete option of the config/scout.php configuration file to true:

'soft_delete' => true,

When this configuration option is true, Scout will not remove soft deleted models from the search index. Instead, it will set a hidden __soft_deleted attribute on the indexed record. Then, you may use the withTrashed or onlyTrashed methods to retrieve the soft deleted records when searching:

and lunar also mentioned this in the doc

By default, scout has the setting soft_delete set to false. You need to make sure this is set to true otherwise you will see soft deleted models appear in your search results

however this doesnt work when searching in the panel with filament table. when set to true, the scout search will not return the records, regardless the table filter already selected "with trashed" or "only trashed"
this PR attemp to fix this

p/s: this is just a quick fix, it might have a better way to detect is the with/only trashed filter is applied before using ->with/onlyTrashed on the scout builder, to get a better search result.

coderabbitai[bot]

This comment was marked as outdated.

Comment thread packages/admin/src/Support/Resources/BaseResource.php Outdated
@lunarphp lunarphp deleted a comment from coderabbitai bot Nov 11, 2025
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Nov 11, 2025
@glennjacobs glennjacobs requested a review from Copilot November 12, 2025 09:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes Scout search functionality when working with soft-deleted models by properly applying trashed filters to Scout queries. The fix ensures that when users select "with trashed" or "only trashed" filters in Filament tables, the Scout search respects these filters by calling the appropriate methods (withTrashed() or onlyTrashed()) on the Scout builder.

Key changes:

  • Added detection of Filament's TrashedFilter state in BaseListRecords.php
  • Applied withTrashed() or onlyTrashed() to Scout queries based on filter state
  • Refactored query building code for improved readability and consistency

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/LunarServiceProvider.php Updated orderBySequence macro to accept iterable instead of array and use blank() helper for better null-safety
packages/admin/src/Support/Resources/BaseResource.php Simplified query building by removing unnecessary variables and consolidating method calls
packages/admin/src/Support/Pages/BaseListRecords.php Added trashed filter detection and applied appropriate Scout methods to handle soft-deleted records

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/admin/src/Support/Pages/BaseListRecords.php
Comment thread packages/admin/src/Support/Pages/BaseListRecords.php Outdated
@lunarphp lunarphp deleted a comment from vercel bot Nov 12, 2025
Comment thread packages/admin/src/Support/Pages/BaseListRecords.php
@alecritson alecritson merged commit 6833143 into lunarphp:1.x Apr 16, 2026
44 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Apr 16, 2026
@wychoong wychoong deleted the fix/scout-search-with-soft-deleted-resource branch April 16, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants