novadaemon/filament-combobox

用于您的 FilamentPHP 表单的侧边栏 combobox 多选字段

v1.0.8 2024-09-03 16:38 UTC

This package is auto-updated.

Last update: 2024-09-03 16:40:44 UTC


README

用于您的FilamentPHP表单的侧边栏 combobox 多选字段。

Cover

安装

您可以通过 composer 安装此包

composer require novadaemon/filament-combobox

此包支持 Filament 3.x

用法

只需像使用其他 Filament 字段一样使用组件。它特别适合资源查看页面,可以完美融合。

use Novadaemon\FilamentCombobox\Combobox;

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('vegetables')
                ->options([
                    'carrot' => 'Carrot',
                    'potato' => 'Potato',
                    'tomato' => 'Tomato',
                ])
            ]);
    }
}

由于 Combobox 组件扩展了 Filament\Forms\Components\Select 类,因此可以使用父组件的几乎所有方法。

与 Eloquent 关联集成

use Novadaemon\FilamentCombobox\Combobox;

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
            ]);
    }
}

自定义

在框中启用搜索

use Novadaemon\FilamentCombobox\Combobox;

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
                ->boxSearchs()
            ]);
    }
}

boxSearchs 方法接受一个布尔值或闭包回调函数。

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
                ->boxSearchs(fn() => auth()->user()->isAdmin())
            ]);
    }
}

修改组件的高度

您可以使用 height 方法更改组件的高度

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
                ->height('500px')
            ]);
    }
}

自定义框的标签

更改框的标签

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
                ->optionsLabel('Available categories')
                ->selectedLabel('Selected categories')
            ]);
    }
}

隐藏框上的标签

class FileResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Combobox::make('categories')
                ->relationship('categories', 'name')
                ->showLabels(false)
            ]);
    }
}

翻译

您可以选择使用以下方式发布翻译:

php artisan vendor:publish --tag="filament-combobox-translations"

现在,您可以修改或添加自定义翻译文件。

贡献

贡献非常简单,非常受赞赏!只需发送 PR 或创建一个问题!

致谢

许可证

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

屏幕截图

Screenshot