Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raobilal4822's avatar

Filament LIvewire update components on change of other components

i am in infolists tab section that is rendering three custom pages like this Tabs\Tab::make('Images') ->icon('heroicon-o-photo') ->schema([ Section::make('') ->schema([ Livewire::make(OwnerimagesWorkorder::class, [ 'record' => $this->record, ])->key('owner-images-table') ]) ->extraAttributes(['style' => 'border: none !important; box-shadow: none !important;']) ->visible($this->record->images() ->where('custom_properties->work_order->share_images_with_unit_owner', true) ->count() > 0) ->hidden(fn() => auth()->user()->type === UserTypeEnum::Tenant->value || auth()->user()->type === UserTypeEnum::CONTRACTORS->value), Section::make('') ->schema([ Livewire::make(tenantimagesWorkorder::class, [ 'record' => $this->record, ])->key('tenant-images-table') ]) ->extraAttributes(['style' => 'border: none !important; box-shadow: none !important;']) ->visible($this->record->images() ->where('custom_properties->work_order->share_images_with_tenant', true) ->count() > 0) ->hidden(fn() => auth()->user()->type === UserTypeEnum::Owner->value || auth()->user()->type === UserTypeEnum::CONTRACTORS->value), Section::make('') ->schema([ Livewire::make(contractorimagesWorkorder::class, [ 'record' => $this->record, ])->key('contractor-images-table') ])->extraAttributes(['style' => 'border: none !important; box-shadow: none !important;']) ->visible($this->record->images() ->where('custom_properties->work_order->share_images_with_contractor', true) ->count() > 0) ->hidden(fn() => auth()->user()->type === UserTypeEnum::Tenant->value || auth()->user()->type === UserTypeEnum::Owner->value), every component have a table like this public function table(Table $table): Table { return $table ->query( fn(): HasMany => $this->record ->images() ->where('custom_properties->work_order->share_images_with_unit_owner', true) ) ->heading('Owner Images') ->columns([ Grid::make() ->columns(1) ->schema(self::getRelationTableColumns()) ]) ->paginated(false) ->contentGrid(['md' => 3, 'xl' => 4]) ->filters([]) ->actions([ ActionGroup::make([ Action::make('Edit') ->label('Edit') ->icon('heroicon-s-pencil') ->form(self::getInformationForm()) ->before(function (Action $action, Media $record,$data) { $parentModel = $record->model_type; $parentId = $record->model_id; $parent = $parentModel::find($parentId);

                        if (!$parent) {
                            Notification::make()->danger()->title('Parent Work Order not found')->send();
                            return;
                        }

                        if (isset($data['media_files']) && is_array($data['media_files'])) {
                            foreach ($data['media_files'] as $fileData) {
                                $file = $fileData['file'] ?? null;
                                $customFileName = $fileData['custom_name'] ?? 'Untitled';

                                if ($file instanceof \Livewire\Features\SupportFileUploads\TemporaryUploadedFile) {
                                    $customProperties = [
                                        'work_order' => [
                                            'share_images_with_contractor' => $data['share_images_with_contractor'] ?? false,
                                            'share_images_with_tenant' => $data['share_images_with_tenant'] ?? false,
                                            'share_images_with_unit_owner' => $data['share_images_with_unit_owner'] ?? false,
                                        ],
                                    ];

                                    $parent->addMedia($file)
                                        ->usingName($customFileName)
                                        ->withCustomProperties($customProperties)
                                        ->toMediaCollection(MediaCollectionEnum::IMAGES->value);

                                        $customProperties = $record->custom_properties ?? [];
                                        $customProperties['work_order']['share_images_with_unit_owner'] = false;
                                        $record->update([
                                            'custom_properties' => $customProperties,
                                        ]);
                                    $allFalse = !(
                                        ($record->custom_properties['work_order']['share_images_with_unit_owner'] ?? false) ||
                                        ($record->custom_properties['work_order']['share_images_with_tenant'] ?? false) ||
                                        ($record->custom_properties['work_order']['share_images_with_contractor'] ?? false)
                                    );
                                    if ($allFalse) {
                                        $record->delete();
                                    }
                                }
                            }

                        } else {
                            $record->update([
                                'name' => $data['custom_name'] ?? $record->name,
                                'custom_properties' => [
                                    'work_order' => [
                                        'share_images_with_contractor' => $data['share_images_with_contractor'] ?? false,
                                        'share_images_with_tenant' => $data['share_images_with_tenant'] ?? false,
                                        'share_images_with_unit_owner' => $data['share_images_with_unit_owner'] ?? false,
                                    ],
                                ],
                            ]);
                        }

                        Notification::make()
                            ->success()
                            ->title('Success')
                            ->body('Image updated successfully.')
                            ->send();

                        $action->cancel();
                    }),

                Action::make('download')
                    ->label('Download')
                    ->icon('heroicon-s-arrow-down-tray')
                    ->action(function (Media $record) {
                        try {
                            return response()->download($record->getPath(), $record->file_name);
                        } catch (\Throwable $e) {
                            Notification::make()
                                ->title('Download Failed')
                                ->body('Could not download this file. Please try again.')
                                ->danger()
                                ->send();
                        }
                    })
                    ->disabled(fn($record) => is_null($record->file_name)),

                Action::make('delete')
                    ->label('Delete')
                    ->icon('heroicon-o-trash')
                    ->requiresConfirmation()
                    ->action(function (Media $record) {
                        $customProperties = $record->custom_properties ?? [];
                        $workOrderProperties = $customProperties['work_order'] ?? [];

                        $workOrderProperties['share_images_with_unit_owner'] = false;
                        $customProperties['work_order'] = $workOrderProperties;
                        $record->custom_properties = $customProperties;

                        $allFalse = !(
                            ($workOrderProperties['share_images_with_contractor'] ?? false) ||
                            ($workOrderProperties['share_images_with_tenant'] ?? false) ||
                            ($workOrderProperties['share_images_with_unit_owner'] ?? false)
                        );

                        if ($allFalse) {
                            $record->delete();
                        } else {
                            $record->save();
                        }
                    })
                    ->after(function () {
                        Notification::make()
                            ->success()
                            ->title('Deleted')
                            ->body('Image has been deleted successfully.')
                            ->send();
                    }),

            ]),
        ], position: ActionsPosition::BeforeColumns)
        ->bulkActions([
            BulkActionGroup::make([
                // Tables\Actions\DeleteBulkAction::make(),
            ]),
        ]);
}

i want when i perfrom any table action on any of the table then i also want to update other component's table . i tried alot but this is not working

0 likes
3 replies
LaryAI's avatar

To update other Livewire components (tables) when you perform an action in any of the tables, you need to emit events from one component and listen for those events in the other components. This is a standard Livewire pattern for cross-component communication.

Step-by-step Solution

1. Emit an Event After Table Actions

In your table actions (such as after editing, deleting, or updating), emit a Livewire event. For example, after a successful update or delete, add:

$this->emit('refreshWorkorderImages');

If you're inside an action closure, use:

Livewire::emit('refreshWorkorderImages');

2. Listen for the Event in All Image Table Components

In each of your Livewire components (OwnerimagesWorkorder, tenantimagesWorkorder, contractorimagesWorkorder), add a listener for this event and refresh the table/query when the event is received.

Example:

class OwnerimagesWorkorder extends Component
{
    protected $listeners = ['refreshWorkorderImages' => '$refresh'];

    // ... rest of your component code
}

Repeat this for tenantimagesWorkorder and contractorimagesWorkorder.

3. Where to Emit the Event

  • In your edit, delete, or any other action that changes the data, after the operation and notification, emit the event:
Notification::make()
    ->success()
    ->title('Success')
    ->body('Image updated successfully.')
    ->send();

$this->emit('refreshWorkorderImages'); // <--- Add this line

$action->cancel();

If you are inside a static closure (not inside $this context), use:

Livewire::emit('refreshWorkorderImages');

4. Why This Works

  • When you emit refreshWorkorderImages, all components listening for it will receive the event.
  • The $refresh directive tells Livewire to re-render the component, so your table will re-query the database and show the updated data.

Summary

  • Emit a custom event after any table action that changes data.
  • Listen for that event in all related Livewire components and refresh them.

Example Recap

In your action:

->after(function () {
    Notification::make()
        ->success()
        ->title('Deleted')
        ->body('Image has been deleted successfully.')
        ->send();

    Livewire::emit('refreshWorkorderImages');
})

In each Livewire component:

protected $listeners = ['refreshWorkorderImages' => '$refresh'];

This will ensure that all three tables update whenever any of them changes.

Please or to participate in this conversation.