F
Filament5mo ago
valeum

Infolist RepeatableEntry with an Array

Hello everyone, I've already searched through the documentation and various sources, but unfortunately I couldn't find a solution to my problem. I'm trying to display dynamic data within an Infolist using RepeatableEntry. Here is a minimal example of my code:
Infolists\Components\RepeatableEntry::make('custom_links')
->label('Links')
->getStateUsing(fn() => [
['label' => 'Google', 'url' => 'https://google.com'],
['label' => 'GitHub', 'url' => 'https://github.com'],
])
->schema([
Infolists\Components\TextEntry::make('label')->label('Title'),
Infolists\Components\TextEntry::make('url')->label('Link'),
]),
Infolists\Components\RepeatableEntry::make('custom_links')
->label('Links')
->getStateUsing(fn() => [
['label' => 'Google', 'url' => 'https://google.com'],
['label' => 'GitHub', 'url' => 'https://github.com'],
])
->schema([
Infolists\Components\TextEntry::make('label')->label('Title'),
Infolists\Components\TextEntry::make('url')->label('Link'),
]),
Even with this static array, nothing is displayed. In the next step, I would like to use $record to access the current record's data dynamically. Does anyone know if this is possible in general, and if so, what I'm doing wrong here? Thank you very much for your help!
1 Reply
corgalore
corgalore5w ago
I'm hoping for a solution to this also. Okay, I found a solution to this. You can create a really simple Entry class that inherits from the RepeatableEntry, then drop it into your schema in place of the RepeatableEntry. Override the setUp() method to set the schema and state. Here's an example: <?php namespace App\Filament\Infolists\Components; use App\Models\Project; use Filament\Infolists\Components\Entry; use Filament\Infolists\Components\RepeatableEntry; use Filament\Infolists\Components\TextEntry; class SoilTestsEntry extends RepeatableEntry { protected string $name = 'soil_tests_entry'; protected function setUp(): void { parent::setUp(); $this->columns(2); $this->schema([ TextEntry::make('id') ->label('ID'), TextEntry::make('formNumber'), TextEntry::make('created') ->label('Created At') ->dateTime('M d, Y g:i A'), ]); $this->state(function ($record) { /* @var Project $record */ if ( $record->soil_tests()->exists() ) { return $record->soil_tests()->get()->map(function($test) { return [ 'id' => $test->Id, 'formNumber' => $test->formNumber, 'created' => $test->created, ]; })->toArray(); } return []; }); } }

Did you find this page helpful?