【问题标题】:How can I create a custom voyager Form Field from package?如何从包中创建自定义 voyager 表单字段?
【发布时间】:2019-11-15 12:20:42
【问题描述】:

我正在尝试创建一个存储库编写器包来为 Voyager 创建一个自定义表单字段,我发现了这个示例:https://github.com/bnku/extended-bread-form-fields,但这对我不起作用。

那么,如何为 Voyager 构建自定义字段表单?结果是这样的:

我尝试了这个存储库示例。

https://github.com/bnku/extended-bread-form-fields(对我不起作用)

这是我的存储库测试:

https://github.com/manuel90/crop-image-field

这是我的 composer.json 我的包:

{
    "name": "manuel90/crop-image-field",
    "description": "New voyager form field to cut image when uploading",
    "authors": [
        {
            "name": "Manuel",
            "email": "testmlzra@gmail.com"
        }
    ],
    "require": {
        "tcg/voyager": "^1.1"
    },
    "autoload": {
        "psr-4": {
            "Manuel90\\CropImageField\\": "src/"
        }
    },
    "extra": {
        "laravel": {
            "providers": [
                "Manuel90\\CropImageField\\CropImageFieldServiceProvider"
            ]
        }
    }
}

我可以看到这些行有问题,它没有检测到“Voyager”类,但我不知道如何解决它:


if( class_exists('Voyager') ) {
    Voyager::addFormField(CropImageFormField::class);
}

https://github.com/manuel90/crop-image-field/blob/master/src/CropImageFieldServiceProvider.php#L34-L36 (根据文档,这是添加自定义表单Docs here 的方法)

我希望在 BREAD 编辑部分中看到输入类型选项中列出的新自定义字段,如下所示:

【问题讨论】:

    标签: php laravel-5 composer-php voyager


    【解决方案1】:

    您需要将Voyager::addFormField 调用移至boot() 方法,因为这算作"piece of functionality",应在正确注册航海服务提供者后调用。

    Voyager 的文档中缺少这一点,因为他们只记录了在应用程序级别添加 FormFields 的用例,在注册方法的调用在所有供应商服务提供者注册后运行。

    【讨论】:

      猜你喜欢
      • 2015-12-12
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多