Showing pivot data in infolist
i'm trying to show some data from a pivot table in my infolist.
The infolist is like this:
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')
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:
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)
]);