ralphjsmit/laravel-filament-components

为 Filament 提供的一组可重用组件。

2.1.0 2024-03-14 10:17 UTC

README

laravel-filament-components

为 Filament 提供的一组可重用组件。

此包收集了方便使用的组件,供您在所有 Filament 项目中使用。它提供了可在几乎所有项目中使用的便捷组件,如侧边栏、时间戳等。

欢迎提出 pull request,如果您自己创建了一个便捷组件,请随时发送 pull request!

安装

您可以通过 composer 安装此包

composer require ralphjsmit/laravel-filament-components

使用方法

目前,以下组件可用

  1. 侧边栏
  2. 时间戳
  3. 更新时间
  4. 创建时间
  5. 删除时间
  6. 时间戳

侧边栏

您可以使用 侧边栏 组件将表单分成两个独立的区域,就像侧边栏一样

use RalphJSmit\Filament\Components\Forms\Sidebar;

Sidebar::make([
    // Components for the main section here
],[
    // Components for the sidebar section here
])

如果您在管理面板中使用它,您可以在 form() 方法中使用 侧边栏

use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use RalphJSmit\Filament\Components\Forms\Timestamps;
use RalphJSmit\Filament\Components\Forms\Sidebar;

public static function form(Form $form): Form
{
    return $form->schema([
        Sidebar::make([
            Section::make()
                ->schema([
                    TextInput::make('title')->label('Title'),
                    // ...
                ]),
            // ...
        ], [
            Section::make()
                ->schema([
                    ...Timestamps::make(),
                    // ...
                ]),
            // ...
        ]),
    ]);
}

侧边栏与 Section 组件配合得非常好,可以在您的界面中定义清晰且易于扫描的区域。

时间戳

使用 时间戳 组件显示记录的“创建时间”和“更新时间”时间戳

use RalphJSmit\Filament\Components\Forms\Timestamps;

return $form->schema([
    ...Timestamps::make(),
    //
]);

时间戳 组件返回一个包含 创建时间更新时间 组件的数组,因此您应该像示例中那样使用数组展开来将组件合并到您自己的数组中。

创建时间

使用 创建时间 组件显示记录的 created_at 时间戳

use RalphJSmit\Filament\Components\Forms\CreatedAt;

return $form->schema([
    CreatedAt::make(),
    //
]);

更新时间

使用 更新时间 组件显示记录的 updated_at 时间戳

use RalphJSmit\Filament\Components\Forms\UpdatedAt;

return $form->schema([
    UpdatedAt::make(),
    //
]);

删除时间

使用 删除时间 组件显示软删除记录的 deleted_at 时间戳

use RalphJSmit\Filament\Components\Forms\DeletedAt;

return $form->schema([
    DeletedAt::make(),
    //
]);

时间戳

使用 时间戳 组件显示记录的定制时间戳。内部,所有上述时间戳都使用此组件。

use RalphJSmit\Filament\Components\Forms\Timestamp;

return $form->schema([
    Timestamp::make('email_verified_at'),
    //
]);

通用

🐞 如果您发现一个错误,请提交详细的 issue,我会尽快修复。

🔐 如果您发现一个漏洞,请查阅 我们的安全策略

🙌 如果您想贡献,请提交 pull request。所有 pull request 都将获得充分认可。如果您不确定我是否会接受您的想法,请随时联系我!

🙋‍♂️ Ralph J. Smit