有没有办法在资源的索引上显示 Laravel\Nova\Fields\Textarea 的前 25 个字符?
只是为了扩展上面的答案,这是我正在使用的函数,它只在切断某些东西时使用省略号:
Text::make('Description')->rules('max:255')->displayUsing(function ($text) {
if (strlen($text) > 30) {
return substr($text, 0, 30) . '...';
}
return $text;
})
Run Code Online (Sandbox Code Playgroud)
小智 6
我们遇到了同样的问题,我们是这样解决的
Text::make('Text *', 'text')
->rules('required')
->hideFromIndex(),
Text::make('Text','text')
->displayUsing(function($id) {
$part = strip_tags(substr($id, 0, 25));
return $part . " ...";
})->onlyOnIndex(),
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
4147 次 |
| 最近记录: |