© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
5 replies
Lukas

Inconsistent behaviour in relation manager dependency injection

Hi, why is it that if I use dependency injection in a relationship manager table row, sometimes the model is loaded with the related relationship records and sometimes not?

For example, in a scenario where
Foo
Foo
has a one-to-many relationship with
Bar
Bar
via the
bars()
bars()
relationship.

Inside the
BarsRelationManager
BarsRelationManager
of the
FooResource
FooResource
I have the following code:

// ...
Tables\Columns\ToggleColumn::make('baz')
    ->updateStateUsing(static function (Bar $record, Foo $ownerRecord, Foo $owner, $livewire) {
        // Attempt to load the bars relationship
        $owner = $owner->load(['bars']);


        $ownerFromLivewire = $livewire->getOwnerRecord();


        dd(
            sizeof($owner->bars),
            sizeof($ownerRecord->bars),
            sizeof($ownerFromLivewire->bars),
        );
    }),
// ...
// ...
Tables\Columns\ToggleColumn::make('baz')
    ->updateStateUsing(static function (Bar $record, Foo $ownerRecord, Foo $owner, $livewire) {
        // Attempt to load the bars relationship
        $owner = $owner->load(['bars']);


        $ownerFromLivewire = $livewire->getOwnerRecord();


        dd(
            sizeof($owner->bars),
            sizeof($ownerRecord->bars),
            sizeof($ownerFromLivewire->bars),
        );
    }),
// ...


The output is something like this:
0
0
3
0
0
3


How come that
$ownerFromLivewire
$ownerFromLivewire
which uses the
$livewire
$livewire
property to get the owner record successfully retrieves the relation records, while
$owner
$owner
which explicitly loads the relationship and
$ownerRecord
$ownerRecord
which does not both do not retrieve the relation records?

I tested it with and without
Model::preventLazyLoading()
Model::preventLazyLoading()
and both return the same results.

Am I missing something?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Relation Manager dependency
FilamentFFilament / ❓┊help
3y ago
Weird relation manager CreateAction behaviour
FilamentFFilament / ❓┊help
5mo ago
Dependency injection.
FilamentFFilament / ❓┊help
3y ago
Dependency Injection in Filament
FilamentFFilament / ❓┊help
2y ago