© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
2 replies
@maticl

RelationManager table action always injects the same record

What I am trying to do:
On a relation manager I have a table action, that displays audit log details.
Not all audit logs have details view, so I dynamically resolve content and visibility based on audit log class.
If you need any more context feel free to ask.

What I did:
I cleared every cache, debugged it, everything seems fine except the injection.
If I log the record in modalContent callback, it always points to the record of the first row in the table (even if we go to page 2, it will point to the record of first row on page 1).
The developer tools network logs dispatch the correct events with correct ids.
log_instance is an Attribute on AuditLog model, that resolves the audit type class with all the data.

My issue/the error:
For some reason, the action modalContent and modalWidth callbacks always get injected with the same record (model of the first row in the table).
Visibility callback works okay.

Code:
use Filament\Tables\Actions\Action;

...

->actions([
      Action::make('view-log')
          ->modalSubmitActionLabel('Close')
          ->modalCancelAction(false)
          ->modalFooterActionsAlignment('end')
          ->modalContent(function (AuditLog $record) {
              if (!$record->log_instance instanceof HasTableViewAction) {
                  return view();
              }
              return view(
                  $record->log_instance->getActionView(),
                  ['auditLog' => $record]
              );
          })
          ->modalWidth(function (AuditLog $record) {
              if (!$record->log_instance instanceof HasTableViewAction) {
                  return 'md';
              }
  
              return $record->log_instance->getModalWidth();
          })
          ->hidden(fn (AuditLog $record): bool => !($record->log_instance instanceof HasTableViewAction))
  
])
use Filament\Tables\Actions\Action;

...

->actions([
      Action::make('view-log')
          ->modalSubmitActionLabel('Close')
          ->modalCancelAction(false)
          ->modalFooterActionsAlignment('end')
          ->modalContent(function (AuditLog $record) {
              if (!$record->log_instance instanceof HasTableViewAction) {
                  return view();
              }
              return view(
                  $record->log_instance->getActionView(),
                  ['auditLog' => $record]
              );
          })
          ->modalWidth(function (AuditLog $record) {
              if (!$record->log_instance instanceof HasTableViewAction) {
                  return 'md';
              }
  
              return $record->log_instance->getModalWidth();
          })
          ->hidden(fn (AuditLog $record): bool => !($record->log_instance instanceof HasTableViewAction))
  
])
Solution
So after some more debugging, i found the issue. It was in the User relationship to the auditLogs.
Since I have two morphs fields in auditLog (parent and related), this specific relationship queries by both of them:

public function allAuditLogs(): MorphMany
  {
      return $this->morphMany(AuditLog::class, 'parent')
          ->orWhere(function ($query) {
              $query->where('related_type', $this->getMorphClass())
                  ->where('related_id', $this->id);
          });
  }
public function allAuditLogs(): MorphMany
  {
      return $this->morphMany(AuditLog::class, 'parent')
          ->orWhere(function ($query) {
              $query->where('related_type', $this->getMorphClass())
                  ->where('related_id', $this->id);
          });
  }

This was not working with the table actions. The table itself was OK, just the actions were not working.
I don't specifically like this solution, as it seems wrong, but I don't have the time to figure out the proper solution. Any tips are welcome.
I changed it to the following, and now it's working:
public function allAuditLogs(): MorphMany
  {
      return $this->morphMany(AuditLog::class, 'parent')
            ->where(function ($query) {
                $query->where(function ($query) {
                    $query->where('related_type', $this->getMorphClass())
                        ->where('related_id', $this->id);
                })->orWhere(function ($query) {
                    $query->where('parent_type', $this->getMorphClass())
                        ->where('parent_id', $this->id);
                });
            });
  }
public function allAuditLogs(): MorphMany
  {
      return $this->morphMany(AuditLog::class, 'parent')
            ->where(function ($query) {
                $query->where(function ($query) {
                    $query->where('related_type', $this->getMorphClass())
                        ->where('related_id', $this->id);
                })->orWhere(function ($query) {
                    $query->where('parent_type', $this->getMorphClass())
                        ->where('parent_id', $this->id);
                });
            });
  }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Table Action always the same record
FilamentFFilament / ❓┊help
2y ago
Injected $record the same for each recordActions Action
FilamentFFilament / ❓┊help
4w ago
RelationManager table action not working
FilamentFFilament / ❓┊help
2y ago
Dispatch Table Record Action
FilamentFFilament / ❓┊help
3mo ago