Infolist is the same for all the records.

I'm trying to list courses in sections (instead of a table). But for every course it returns the same data (data of the last course) in the infolist. The header and the description of the course are displayed correctly.
public function content(Schema $schema): Schema
{
return $schema
->columns([
'default' => 3,
])
->components($this->getTableRecords()->sortBy('start_at')->map(function ($course) use ($schema) {

$infolist = CourseResource::infolist($schema)->record($course)->getFlatComponents(withAbsoluteKeys: true);

unset($infolist['name']);
unset($infolist['description']);
unset($infolist['start_enrollment_at']);
unset($infolist['end_enrollment_at']);

return Section::make($course->name)
->model($course)
->description($course->description)
->schema([
...$infolist,
Action::make('view')
->label('Bekijk cursus')
->url(fn () => ViewCourse::getUrl(['record' => $course]))
->button(),
]);
})->toArray());
}
public function content(Schema $schema): Schema
{
return $schema
->columns([
'default' => 3,
])
->components($this->getTableRecords()->sortBy('start_at')->map(function ($course) use ($schema) {

$infolist = CourseResource::infolist($schema)->record($course)->getFlatComponents(withAbsoluteKeys: true);

unset($infolist['name']);
unset($infolist['description']);
unset($infolist['start_enrollment_at']);
unset($infolist['end_enrollment_at']);

return Section::make($course->name)
->model($course)
->description($course->description)
->schema([
...$infolist,
Action::make('view')
->label('Bekijk cursus')
->url(fn () => ViewCourse::getUrl(['record' => $course]))
->button(),
]);
})->toArray());
}
Solution:
Seems like I fixed it by adding ->state(fn ($record) => $record->the_attribute_name))to all the components in the infolist.
Jump to solution
4 Replies
bachir
bachir3w ago
I have the same problem
Solution
Merdin
Merdin3w ago
Seems like I fixed it by adding ->state(fn ($record) => $record->the_attribute_name))to all the components in the infolist.
bachir
bachir3w ago
When I try to dump the selected record inside a table action using dd($record), it always returns the first record of the table — no matter which record I actually click on.
Dennis Koch
Dennis Koch3w ago
Doesn't look like a bug. You need to set the state somehow You could probably also just use ->state($record->toArray()) on the Section

Did you find this page helpful?