ibrostudio / filament-plugin-tools

这是我创建的包 filament-plugin-tools

v1.0.1 2022-06-05 07:56 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

此包用于Filament插件开发。

它简单地将原生Filament命令转换为插件上下文,以生成资源、页面和小部件。

注意

为了轻松入门,我们发布了Spatie的package-skeleton-laravel的Filament版本,包括这些工具和其他一些好东西。查看这里:filament-plugin-skeleton

要求

假设你正在开发一个名为PluginName的插件。文件位于一个专门的目录中,称为packages。你已经在Laravel应用程序中本地导入插件以进行开发

composer.json

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/plugin-name"
        }
    ]
}

然后

composer require vendor-name/plugin-name
自动注册

此包可以自动在插件服务提供者中注册资源、页面和小部件。

为此,请确保

  1. 你已将你的服务提供者的完全限定类名添加到插件composer.json文件中的extra.laravel.providers数组中
{
    "extra": {
        "laravel": {
            "providers": [
                "VendorName\\PluginName\\PluginNameServiceProvider"
            ]
        }
    }
}
  1. 在插件的服务提供者文件中添加$pages$resources$widgets属性
use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;

class PluginNameServiceProvider extends PluginServiceProvider
{
    protected array $pages = [
    ];

    protected array $resources = [
    ];

    protected array $widgets = [
    ];

    public function configurePackage(Package $package): void
    {
        $package->name('plugin-name');
    }
}

安装

使用composer在Laravel应用程序中安装filament-plugin-tools包

composer require ibrostudio/filament-plugin-tools --dev

使用方法

资源
php artisan make:filament-plugin-resource plugin-name Model

选项与原始命令相同

php artisan make:filament-plugin-resource plugin-name Model --simple
php artisan make:filament-plugin-resource plugin-name Model --generate
php artisan make:filament-plugin-resource plugin-name Model --view-page
etc...
关系管理器

所有关系管理器都可用

php artisan make:filament-plugin-has-many ModelResource relationship attribute
php artisan make:filament-plugin-has-many-through ModelResource relationship attribute
php artisan make:filament-plugin-belongs-to-many ModelResource relationship attribute
php artisan make:filament-plugin-morph-many ModelResource relationship attribute
php artisan make:filament-plugin-morph-to-many ModelResource relationship attribute
页面
php artisan make:filament-plugin-page plugin-name PageName

选项也适用

php artisan make:filament-plugin-page plugin-name Model --resource=ModelResource --type=custom
小部件
php artisan make:filament-plugin-widget plugin-name WidgetName

使用资源选项

php artisan make:filament-plugin-widget plugin-name Model --resource=ModelResource

测试

composer test

致谢

许可

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