Repeater Fields to TextColumn
Hi, I have a Repeater with one field stage_name and I need to display it in table but when I display it shows all stages name how to show only the last stage name?
Thank you!
Solution:Jump to solution
Thank you guys for all answers I just solved with Laravel Attribute (Casts) function and made all logic inside and it works perfectly.
14 Replies
Can you provide the code and what you are seeing
Like this I need to display only the last one this is in table and it came from the repeater fields
I tried with modifiying the query but does not work throwing errors
we need to see the code you are using?
otherwise
Let me try this
TextColumn::make('stages.stage.name')
->label('المرحلة')
->formatStateUsing(fn (string $state): string => array_pop($state))
->badge(),
It throws error: array_pop(): Argument #1 ($array) must be of type array, string givenTextColumn::make('stages.stage')
Why don't you have the stage return the relationship latest element?
I didn't understand
Hi,
Your mistake is using
array_pop()
which apply to arrays, because the result is a collection and not an array.
Try something like this:
Let me try I appreciate it for your answer.
It throws me an error: Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::last()
Ok, so try to display the content of $state and tell us what you have:
What is this
last()
?Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Solution
Thank you guys for all answers I just solved with Laravel Attribute (Casts) function and made all logic inside and it works perfectly.
You may have noticed that I mentioned Collection, so here:
https://laravel.com/docs/11.x/collections#method-last
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.