Skip to content
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

Dispatch event on sortable update #177

Closed
wants to merge 1 commit into from
Closed

Conversation

chrispage1
Copy link
Contributor

When sorting is performed, there is currently no way to clear the cache (just one use case).

This contribution fixes this by dispatching an event.

The event dispatch allows us to listen for an event and perform whatever we need to do after the sort.

I have also added a convenience method called isFor which allows you to check directly against another string or model instance.

An example usage of this would be:

use Spatie\EloquentSortable\EloquentModelSortedEvent as SortEvent;

class SortingListener
{

    public function handle(SortEvent $event): void {
        if ($event->isFor(MyClass::class)) {
            // ToDo: flush our cache
        }
    }
}

Thanks!

@chrispage1 chrispage1 closed this May 31, 2024
@chrispage1
Copy link
Contributor Author

Closed because I noticed I'd merged main 🤦

Sorry!

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.

1 participant