Skip to content

Commit cc28a5d

Browse files
fix(inspection-plans): broadcast archival of prior versions on publish
publish() retired other versions via a mass query-builder update, which skips Eloquent events — so the realtime inspection_plans collection didn't reflect the newly-archived version until a page reload. Update each row as a model instead so its change broadcasts immediately.
1 parent d00f55e commit cc28a5d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

backend/app/Services/Quality/InspectionPlanVersionService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ public function publish(InspectionPlan $plan): InspectionPlan
5353
return DB::transaction(function () use ($plan) {
5454
$rootId = $plan->rootId();
5555

56+
// Retire the other versions one model at a time (not a mass
57+
// query-builder update) so each row fires its model events and the
58+
// realtime collection reflects the archival immediately.
5659
InspectionPlan::query()
5760
->where(fn ($q) => $q->where('id', $rootId)->orWhere('root_id', $rootId))
5861
->where('id', '!=', $plan->id)
59-
->update(['is_active' => false]);
62+
->where('is_active', true)
63+
->get()
64+
->each(fn (InspectionPlan $other) => $other->update(['is_active' => false]));
6065

6166
$plan->update([
6267
'published_at' => now(),

0 commit comments

Comments
 (0)