F
Filament14mo 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
torrivOP14mo ago
Bump
Solution
torriv
torriv14mo 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
torrivOP14mo ago
If someone has a better way, let me know 🙂
Hussain4real
Hussain4real13mo ago
The easiest way is to do this
Infolists\Components\TextEntry::make('pivot.repetitions')
Infolists\Components\TextEntry::make('pivot.repetitions')
Want results from more Discord servers?
Add your server