F
Filament16mo ago
torriv

Showing pivot data in infolist

i'm trying to show some data from a pivot table in my infolist. The infolist is like this:
public static function infolist(Infolist $infolist) : Infolist{

return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')->label('Reps'),
TextEntry::make('sets')->label('Set'),
TextEntry::make('rest')->label('Pause'),
])
->columns(4)
]);
}
public static function infolist(Infolist $infolist) : Infolist{

return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')->label('Reps'),
TextEntry::make('sets')->label('Set'),
TextEntry::make('rest')->label('Pause'),
])
->columns(4)
]);
}
The 'exercise_name' is showing, but that is from the parent table. but the rest is in the pivot table. i've tried to add the name of the pivot table, but that didn't work either. (like 'nameOfPivotTable.repetitions')
Solution:
for the moment i solved it doing this: ```php return $infolist ->schema([ TextEntry::make('program_name'),...
Jump to solution
4 Replies
torriv
torrivOP16mo ago
Bump
Solution
torriv
torriv16mo ago
for the moment i solved it doing this:
return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->repetitions)
->label('Reps'),
TextEntry::make('sets')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->sets)
->label('Set'),
TextEntry::make('rest')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->rest)
->label('Pause'),
])
->columns(4)
]);
return $infolist
->schema([
TextEntry::make('program_name'),
RepeatableEntry::make('WorkoutExercises')
->schema([
TextEntry::make('exercise_name')->label('Øvelse'),
TextEntry::make('repetitions')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->repetitions)
->label('Reps'),
TextEntry::make('sets')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->sets)
->label('Set'),
TextEntry::make('rest')
->getStateUsing(fn (WorkoutExercise $record): string => $record->pivot->rest)
->label('Pause'),
])
->columns(4)
]);
torriv
torrivOP16mo ago
If someone has a better way, let me know 🙂
Hussain4real
Hussain4real14mo ago
The easiest way is to do this
Infolists\Components\TextEntry::make('pivot.repetitions')
Infolists\Components\TextEntry::make('pivot.repetitions')

Did you find this page helpful?