gkermer/nova-text-auto-complete

Laravel Nova 文本自动完成字段。

0.0.5 2020-08-28 14:44 UTC

This package is auto-updated.

Last update: 2024-09-22 22:17:36 UTC


README

这个Nova字段提供了在文本输入字段内自动完成搜索结果的功能。

Nova text with autocomplete demo

安装

您可以通过composer将Nova字段安装到使用Nova的Laravel应用程序中

composer require gkermer/nova-text-auto-complete

用法

要添加自动完成文本字段,请在您的Nova资源中使用Gkermer\TextAutoComplete\TextAutoComplete字段

use Gkermer\TextAutoComplete\TextAutoComplete;
TextAutoComplete::make('Favourite Fruit')->items([
    'Apple',
    'Apricots',
    'Avocado',
    'Banana',
    'Blueberries',
]),

假设您有一个Eloquent模型Fruit,具有属性name,您可以按以下方式获取条目

TextAutoComplete::make('Favourite Fruit')->items(
    Fruit::pluck('name')
),

然而,假设Fruit有数百或数千条记录,下拉选择菜单中填充了如此多的项目。那么您可以这样找到条目

TextAutoComplete::make('Favourite Fruit')->items(function($search) {
    return Fruit::where('name', 'like', '%' . $search . '%')
        ->get()
        ->pluck('name');
}),

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件