F
Filamentβ€’11mo ago
Trauma Zombie

How to show simple array on view page?

Hey guys, in my model I have simple array attribute answers in this format:
[
"Gender" => "male",
"Age" => "24",
...
]
[
"Gender" => "male",
"Age" => "24",
...
]
I want to display it in my resource view page:
Infolists\Components\Section::make(__('Answers'))
->icon('heroicon-o-question-mark-circle')
->schema([
Infolists\Components\RepeatableEntry::make('answers')
->hiddenLabel()
->schema([
Infolists\Components\TextEntry::make('0')
->label(__('Question')),

Infolists\Components\TextEntry::make('1')
->label(__('Answer')),
]),
])
->collapsible(),
Infolists\Components\Section::make(__('Answers'))
->icon('heroicon-o-question-mark-circle')
->schema([
Infolists\Components\RepeatableEntry::make('answers')
->hiddenLabel()
->schema([
Infolists\Components\TextEntry::make('0')
->label(__('Question')),

Infolists\Components\TextEntry::make('1')
->label(__('Answer')),
]),
])
->collapsible(),
Can you help me, how to do it correctly?
Solution:
custom view I think ```html <!-- custom.blade.php --> <div>...
Jump to solution
4 Replies
LeandroFerreira
LeandroFerreiraβ€’11mo ago
->schema([
TextEntry::make('answers.Gender')
->label('Gender'),
TextEntry::make('answers.Age')
->label('Age')
])
->schema([
TextEntry::make('answers.Gender')
->label('Gender'),
TextEntry::make('answers.Age')
->label('Age')
])
?
Trauma Zombie
Trauma ZombieOPβ€’11mo ago
These array keys are not the same for each.
Solution
LeandroFerreira
LeandroFerreiraβ€’11mo ago
custom view I think
<!-- custom.blade.php -->
<div>
@foreach ($getState() as $key => $value)
<div class="flex gap-2">
<div>{{ $key }}</div>
<div>{{ $value }}</div>
</div>
@endforeach
</div>
<!-- custom.blade.php -->
<div>
@foreach ($getState() as $key => $value)
<div class="flex gap-2">
<div>{{ $key }}</div>
<div>{{ $value }}</div>
</div>
@endforeach
</div>
ViewEntry::make('answers')
->view('custom')
ViewEntry::make('answers')
->view('custom')
Trauma Zombie
Trauma ZombieOPβ€’11mo ago
This is good, thank you. πŸ™‚
Want results from more Discord servers?
Add your server