I'm facing an issue while trying to pass a callback function to the url() method within a RepeatableEntry. My goal is to dynamically add a link to a title within the context of a JSONB column named 'blog'.
Here's a snippet of my code:
RepeatableEntry::make('event.races')->hiddenLabel()
->schema([
TextEntry::make('name')->label('Race name')->inlineLabel(),
RepeatableEntry::make('content.blog')->label('Race Reports')
->schema([
TextEntry::make('title')->label('Blog Title')->url(function ($state, $record) {
// The following line is causing an error
return $record->event->races->first()->content->blog->link;
}),
TextEntry::make('link')->label('Link'),
]),
RepeatableEntry::make('content.vlog')->label('Vlogs')
->schema([
TextEntry::make('title')->label('Vlog Title'),
TextEntry::make('link')->label('Vlog Link'),
]),
])
In this context, 'blog' is a JSONB column containing title and link key-value pairs. However, when trying to access the link using $record->event->races->first()->content->blog->link, I encounter the error "Attempt to read property 'link' on array.
When I do this
dd($record->event->races->first()->content->blog);
I got this
array:3 [▼ // app/Filament/Resources/EventInstanceResource.php:224
0 => array:2 [▼
"title" => "Quia eaque pariatur"
"link" => "Ipsa ipsa beatae e"
]
1 => array:2 [▶]
2 =>
How can I dynamically retrieve the link from the JSONB column within the current iteration of the relationship?