mahmudkuet11/nova-multiselect-field

Laravel Nova 的多选字段。

1.5.0 2019-08-13 18:20 UTC

This package is auto-updated.

Last update: 2024-09-14 05:21:59 UTC


README

Laravel Nova 包为 Nova 的字段集合添加了多选功能。

屏幕截图

Detail View

Form View

Index View

安装

使用 Composer 在 Laravel Nova 项目中安装此包

composer require mahmudkuet11/nova-multiselect-field

用法

该字段的使用方法类似于 Nova 的原生选择字段。数据库中的字段类型应为基于文本的(即 stringtextvarchar),所选值存储为 JSON 数组。

use Mahmud\MultiselectField\Multiselect;

public function fields(Request $request)
{
    return [
      Multiselect
        ::make('Favourite football teams', 'football_teams')
        ->options([
          'liverpool' => 'Liverpool FC',
          'tottenham' => 'Tottenham Hotspur',
          'bvb' => 'Borussia Dortmund',
          'bayern' => 'FC Bayern Munich',
          'barcelona' => 'FC Barcelona',
          'juventus' => 'Juventus FC',
          'psg' => 'Paris Saint-Germain FC',
        ])

        // Optional:
        ->placeholder('Choose football teams')
        ->max(4)
        ->optionsLimit(5)
    ];
}

选项

您可以传递给字段的可能选项,例如使用选项名称作为函数,即 ->placeholder('选择花生')

致谢

许可证

此项目是开源软件,采用 MIT 许可证