Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Nova - How to display partial textarea text on index

Tags:

laravel-nova

Is there a way to display the first 25 chars of a Laravel\Nova\Fields\Textarea on the index of a Resource?

like image 757
Michael Pawlowsky Avatar asked Dec 06 '22 10:12

Michael Pawlowsky


1 Answers

We had the same problem and we solved it like this

Text::make('Text *', 'text')
            ->rules('required')
            ->hideFromIndex(),

Text::make('Text','text')
    ->displayUsing(function($id) {
        $part = strip_tags(substr($id, 0, 25));
        return $part . " ...";
    })->onlyOnIndex(),

hope this helps.

like image 138
Macolson Avatar answered Dec 30 '22 20:12

Macolson