saade/filament-extra

一组可重用的 Filament 辅助工具、列、字段、操作等!

资助包维护!
saade

v3.2.0 2024-03-12 16:10 UTC

This package is auto-updated.

Last update: 2024-09-08 04:11:38 UTC


README

Latest Version on Packagist Total Downloads

一组可重用的 Filament 辅助工具、列、字段、操作等!

安装

您可以通过 composer 安装此包

composer require saade/filament-extra

表单

关系管理器

此字段允许您在表单内渲染一个 关系管理器。如果您需要在标签页或模态框中渲染它,则非常有用。

use Saade\FilamentExtra\Forms\Components\RelationManager;
use App\Filament\Resources\YourResource\RelationManagers\YourRelationManager;

RelationManager::make(YourRelationManager::class)
    ->lazy(bool $lazy = true)

颜色选择

此字段允许您从您的应用程序中选择 Filament 颜色。

use Saade\FilamentExtra\Forms\Components\ColorSelect;

ColorSelect::make('color')

关注点

trait HasSoftDeletedRecords

厌倦了在每个资源中重写 getEloquentQuery 方法?此特性将为您处理软删除。

use Filament\Resources\Resource;

use Saade\FilamentExtra\Concerns\HasSoftDeletedRecords;

class YourResource extends Resource
{
    use HasSoftDeletedRecords;
}

trait NavigationGroupAwareBreadcrumbs

此特性将为您处理面包屑。如果您需要为属于导航组的资源渲染面包屑,则非常有用。

use Filament\Resources\Pages\CreateRecord;

use Saade\FilamentExtra\Concerns\NavigationGroupAwareBreadcrumbs;

class CreateYourRecord extends CreateRecord
{
    use NavigationGroupAwareBreadcrumbs;
}

trait HasParentResource

此特性将为您处理嵌套资源。如果您想了解更多信息,请阅读博客文章。此代码部分来自 LaravelDaily/filament-nested-resources 并贡献回社区。

  1. $parentResource 属性添加到您的子资源中。
use Filament\Resources\Resource;

class ChildResource extends Resource
{
    public static ?string $parentResource = ParentResource::class;
}
  1. 将子资源页面添加到父资源中。
use Filament\Resources\Resource;

class ParentResource extends Resource
{
    public static function getPages(): array
    {
        return [
            'index' => Pages\ManageParents::route('/'),
            'edit' => Pages\EditParent::route('/{record}/edit'),

            // Please note that 'child' can be anything you want. It defaults to the resource slug.
            // If you want to change it, you need to override the $pageNamePrefix property on the child resource pages.
            'child.index' => ChildResource\Pages\ListChildren::route('/{parent}/children'),
            'child.create' => ChildResource\Pages\CreateChild::route('{parent}/children/create'),
            'child.edit' => ChildResource\Pages\EditChild::route('{parent}/children/{record}/edit'),
        ];
    }
}
  1. 将特性添加到您的子资源页面中。
use Filament\Resources\Pages\ListRecords;

use Saade\FilamentExtra\Concerns\HasParentResource;

class ListChildren extends ListRecords
{
    use HasParentResource;

    // (optional) Define custom relationship key (if it does not match the table name pattern).
    protected ?string $relationshipKey = 'parent_id';

    // (optional) Define custom child page name prefix for child pages (if it does not match the parent resource slug).
    protected ?string $pageNamePrefix = 'child';
}

支持

class Color

此类帮助您与 Filament 颜色交互。如果您需要将颜色转换为十六进制值或选择一个色调以 collect() Filament 颜色,则非常有用。

use Saade\FilamentExtra\Support\Color;

Color::make(name: 'fuchia', shade: 200)
  ->shade(int $shade = 500)   // Set a shade
  ->get()                     // Returns the color as array of shades
  ->toHex()                   // Returns the color as hex value
  ->toRgb()                   // Returns the color as rgb value
  ->collect()                 // Returns the color as a Laravel Collection

function color

此函数是 Color 类的快捷方式。

use function Saade\FilamentExtra\Support\color;

color(name: 'fuchia', shade: 200)
  ->shade(int $shade = 500)   // Set a shade
  ->get()                     // Returns the color as array of shades
  ->toHex()                   // Returns the color as hex value
  ->toRgb()                   // Returns the color as rgb value
  ->collect()                 // Returns the color as a Laravel Collection

function html

使用此函数作为 Illuminate\Support\HtmlString 类的快捷方式。

use Filament\Forms;

use function Saade\FilamentExtra\Support\html;

Filament\Forms\Components\SomeField::make()
  ->label(
    html('<span class="text-red-500">*</span> Label')
  )

function md

使用此函数作为 Illuminate\Support\HtmlString 类的快捷方式以将 Markdown 转换为 HtmlString。

use Filament\Forms;

use function Saade\FilamentExtra\Support\md;

Filament\Forms\Components\SomeField::make()
  ->label(
    md('### Label')
  )

function blade

使用此函数渲染 blade 模板。

use Filament\Forms;

use function Saade\FilamentExtra\Support\blade;

Filament\Forms\Components\SomeField::make()
  ->label(
    blade('<x-heroicon::some-icon class="w-5 h-5" /> Label', ['some' => 'data'])
  )

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全漏洞

请审查我们的安全策略以了解如何报告安全漏洞。

鸣谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。