Reordering and Observers
what's the trick to triggerng an observer from a filament table : ->reorderable('sort'); ? I need to clear cache on reordering items. I set an Observer but the updating of sort records is not triggering the models observer
Solution:Jump to solution
Instead of triggerring an event, override the method returning the parent then handle your after event changes i.e.
https://github.com/filamentphp/filament/discussions/6619...
GitHub
Event or Closure after reordering table? · filamentphp filament · D...
Perchance, is it possible to set up an event after reordering a table with ->reorderable()? Or maybe pass a Closure that in some way is executed after reordering?
7 Replies
Observers wouldn't be triggerred from a table, they are triggered by model events. So we would load each and update the record and if the record is updated i.e. (Saved) it should trigger the observer
but the reorderable() is updating the model. or am I missing something?
If you have clicked save then yet the observer should be triggered. Is the observer triggered for create/edit?
yes it is in the edit page . but on the table the sort field is updated on all records the ordering so there is an update event
The issue looks to be we are not handling it per model for performance we do a single query update. i.e.
update
contacts
set
order
= case
when id = '2' then 1
when id = '1' then 2
when id = '4' then 3
when id = '6' then 4
when id = '8' then 5
when id = '10' then 6
when id = '5' then 7
when id = '19' then 8
end,
contacts
.updated_at
= '2025-02-06 10:42:58'
where
id
in ('2', '1', '4', '6', '8', '10', '5', '19')
Which would mean a model update isn't triggered. Let me see if we have an eventSolution
Instead of triggerring an event, override the method returning the parent then handle your after event changes i.e.
https://github.com/filamentphp/filament/discussions/6619
GitHub
Event or Closure after reordering table? · filamentphp filament · D...
Perchance, is it possible to set up an event after reordering a table with ->reorderable()? Or maybe pass a Closure that in some way is executed after reordering?
I managed to use this in the ListResource.