Skip to content

[10.x] searchableSync / unsearchableSync #920

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

Merged

Conversation

gdebrauwer
Copy link
Contributor

In my projects, I always configure Scout to queue the jobs that make model(s) searchable or unsearchable. This works perfectly, but sometimes you want to make a model instantly unsearchable.
For example, in a project, I show a list that is based on a Scout search result. Each item has a delete button. Deleting an item and refreshing the list will mean the refreshed list has a high change of still containing the deleted item if the job that makes the item unsearchable has not finished yet.

This PR adds methods to easily make model(s) synchronously searchable/unsearchable even if Scout config will queue those actions by default.

config()->set('scout.queue', true);

// This will be queued
$models->searchable();
$models->unsearchable();

// This will happen synchronously even if 'scout.queue' config variable is set to true
$models->searchableSync();
$models->unsearchableSync();

The 'Sync' suffix for the method names is inspired by the 'dispatchSync' method on jobs in Laravel.

@gdebrauwer gdebrauwer marked this pull request as draft March 27, 2025 16:32
@gdebrauwer gdebrauwer marked this pull request as ready for review March 27, 2025 16:34
@taylorotwell taylorotwell merged commit 651773c into laravel:10.x Mar 27, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants