Show Repeaters first entry in Table View
I would like to show an entry in the Table View of Component. How can i access this data? This is my repeater:
25 Replies
I'm not sure I completely understand your question, but if you are trying to access data from within the repeater you need to use something like
$get(../formField)
to go one level up from the repeater
If you're trying to access data from outside the repeater, you would use $get('dates')
and then that would give you an array of all the repeaters, which you could use a loop to go through and pull dataThanks for the reply. I would like to use it here in the TABLE VIEW. But sth. like dates[0].date is not working as it cannot read the array here this way
Oh... I don't know if that is possible
Can you explain more about what you are trying to accomplish?
There might be a different way to do it
->formatStateUsing() you can grab the first item in the array and return it as the state for the column.
@awcodes thanks - can you show me how this is done in my example? I only get an "array to string" conversion error. my
dates
json field looks like this:
In your case $state is the array.
So it should be like this:
->formatStateUsing(fn (string $state): string => __("dates.{$state['date']}"))
but is does not return anything @awcodesNo. And why are you trying to translate the date?
Just return $state[0][‘date’]
Still no return. Is still empty even though there's an entry in the db
dd($state) what does it show.
That is the weird part. Errors are executed and shown, but i can not dd nor Debugbar::info() anything a this point.
I am within a RelationsManager. Might this be part of the problem?
No, it’s still a table
Make sure you have the appropriate cast on your model too.
is cast as array
the return you sent is missing the
dates
isn't it?No dates it’s the name of the field. $state is the vale of dates.
Then i get the error Array to string conversion
if i name the field "dates"
Unless dates is a key in a larger json structure that you aren’t showing.
dates is the name of the repeater
Forms\Components\Repeater::make('dates')
. see first messageRight, but the names of the form field should be the same as the column on your model.
And it’s the same for tables.
So $state is the value of that column
Your form looks fine.
if i name the column
dates
i get the array to string errorSo, dd($state[0][‘date’])
I really can’t debug for you. 🙂
i know. but debugging is not working. As i wrote… as soon as i name the TextColumn
dates
i get the array to string error. If i name it differntly i can not dd...
Filament does not let me name the Table Field the same as the Form field... array to string error
@awcodes this is working btw: