Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SNaRe's avatar
Level 7

Dynamically Retrieve and pass Link from JSONB Column within RepeatableEntry

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?

0 likes
1 reply
SNaRe's avatar
Level 7

I solved it by searching the title inside the array and getting the value, but I wouldn't say I liked this solution.

TextEntry::make('title')->label('Blog Title')->url(function ($state, $record) {

    foreach ($record->event->races->first()->content->blog as $item) {
        if (isset($item['title']) && $item['title'] == $state) {
            return $item['link'];
        }
    }
}),

Please or to participate in this conversation.