F
Filament15mo ago
Vp

infolist with relationship not working

I create infolist, play around with table and display in home page.. I can get actual record data and it displaying correct, but it cannot show relationship data. My code:
public function lyricLists(Infolist $infolist): Infolist
{
return $infolist
->state([
'lyrics' => $this->getTableRecords(),
])
->schema([
RepeatableEntry::make('lyrics')
->label('')
->schema([
TextEntry::make('album.name') // not working
->label(''),
TextEntry::make('title') // working
->label(''),
TextEntry::make('lyrics') // working
->label(''),
]),
]);
}

public function table(Table $table): Table
{
return $table
->query(
Lyric::query()
->with('album')
->latest(),
);
}
public function lyricLists(Infolist $infolist): Infolist
{
return $infolist
->state([
'lyrics' => $this->getTableRecords(),
])
->schema([
RepeatableEntry::make('lyrics')
->label('')
->schema([
TextEntry::make('album.name') // not working
->label(''),
TextEntry::make('title') // working
->label(''),
TextEntry::make('lyrics') // working
->label(''),
]),
]);
}

public function table(Table $table): Table
{
return $table
->query(
Lyric::query()
->with('album')
->latest(),
);
}
If I dd() inside table() and yes I got data with relationships, what should be the problem?
Solution:
This happen because I have boolean column "album" cast to boolean, and relationship name "album".. I've changed to different name and it working fine
Jump to solution
2 Replies
Vp
VpOP15mo ago
For now I make it working like below, without calling relationship.. but hope it works with relationship as docs
TextEntry::make('album_id')
->label('')
->formatStateUsing(function (Lyric $lyric) {
return Album::find($lyric->album_id)->value('name');
})
TextEntry::make('album_id')
->label('')
->formatStateUsing(function (Lyric $lyric) {
return Album::find($lyric->album_id)->value('name');
})
Solution
Vp
Vp15mo ago
This happen because I have boolean column "album" cast to boolean, and relationship name "album".. I've changed to different name and it working fine
Want results from more Discord servers?
Add your server