FilamentF
Filament10mo ago
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'))


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!
Was this page helpful?