© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•11mo ago•
3 replies
Ngannv

Call to a member function getRelated() on null

I am encountering an issue while using Filament and Eloquent in Laravel. Specifically, I am trying to display the district.name column from the Homestays table, but when there is a record in the homestays table with district_id=1000 and there is no corresponding record in the district table with id=1000, I get the following error:

Call to a member function getRelated() on null
Here’s the code I’m using:


TextColumn::make('district.name')
    ->label(__('db.district'))
TextColumn::make('district.name')
    ->label(__('db.district'))



The issue: When the district_id in the homestays table does not have a matching record in the district table, I get the error mentioned above. I want to know if there’s a way to handle this scenario without causing an error, for example, by displaying a default value or skipping records without related data?

Additional information:

I am using an Eloquent belongsTo relationship between Homestay and District.

Records in district_id are not always valid or existing.

Thanks in advance for any help!
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

Call to a member function getRelated() on null
FilamentFFilament / ❓┊help
5mo ago
Call to a member function makeGetUtility() on null
FilamentFFilament / ❓┊help
5mo ago
call to a member function relation() on null
FilamentFFilament / ❓┊help
10mo ago
Call to a member function isRelation() on null
FilamentFFilament / ❓┊help
11mo ago