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

pickab00's avatar

Adding displayUsing method to different methods

So I have added fields to nova with the displayUsing() method which I am using to trim down the string to shorten it. I want to shorten it only on the index/table view and not on the show. Currently what I have is this:

Text::make('data')
                ->displayUsing(function ($text) {
                    if (strlen($text) > 30) {
                        return substr($text, 0, 30) . '...';
                    }
                    return $text;
                }),

Which is correct and I can successfully trim the text down to 30 characters but this applies to all view including show. How can I not trim the show method and just the index?

0 likes
1 reply
pickab00's avatar
pickab00
OP
Best Answer
Level 4

For anyone asking, Nova has methods where you can show a specific field on a specific page (index, update etc). So just use the onlyOnIndex() to show the above trimmed code and onlyOnDetail() to show it on the detail page without the displayUsing method

1 like

Please or to participate in this conversation.