septio/laravel-nova-meaning-cloud

用于Laravel Nova的字段,通过使用Meaning Cloud的API从另一个文本字段生成摘要文本。

1.0 2020-01-30 12:05 UTC

This package is auto-updated.

Last update: 2024-09-06 00:30:47 UTC


README

用于Laravel Nova的字段,通过使用Meaning Cloud的API从另一个文本字段生成摘要文本

此包需要Meaninccloud.com(别担心,它是免费的)上的账户

安装

您可以通过Composer将此包安装到使用Nova的Laravel应用程序中

$ composer require septIO/LaravelNovaMeaningCloud

在您的.env文件中添加以下行

MEANINGCLOUD_KEY=[Your Meaning Cloud API key]

用法

将字段导入您的Nova资源

use Septio\LaravelMeaningcloud\LaravelMeaningcloud;

将字段添加到您的fields[]数组中

public function fields(Request $request)
    {
        return [
            //... Rest of fields
            LaravelMeaningcloud::make("resume")->from("Body")->sentences(5)->hideFromIndex(),
        ];
    }

该字段需要2个输入:make("table column"),如常,这里的make指的是该字段写入/读取的表列。

from("Other Field Name")是应该从中进行文本摘要的字段。

sentences(x)是可选的。如果设置为数字,则从from()中摘要的文本将总结为x个句子。默认为3

示例

让我们设置一个简单的博客

public function fields(Request $request){
    return [
        Text::make("title"),
        Trix::make("body"), // We'll use the builtin Trix editor for the body
        LaravelMeaningCloud::make("resume")->from("Body"),
        BelongsTo::make("author")
    ];
}

from需要与引用字段的占位符匹配,而不是名称。原因将在下一个示例中展示。

让我们更改正文字段的显示名称

public function fields(Request $request){
    return [
        Text::make("title"),
        Trix::make("Text to display", "body"), // Now "Body" doesn't work anymore
        LaravelMeaningCloud::make("resume")->from("Text to display"), // We'll have to use "Text to display"
        BelongsTo::make("author")
    ];
}

注意

该工具依赖于Meaninccloud.com的AI,因此结果可能会有所不同。