定制 futuraddb/twill-geo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

futuraddb/twill-geo

最新稳定版本:v1.0.3

Composer 安装命令:

composer require futuraddb/twill-geo

包简介

This package allows you to easily manage Geo Structured Data (JSON-LD) for your Twill models.

README 文档

README

This package allows you to easily manage Geo Structured Data (JSON-LD) for your Twill models.

It works by adding a temporary field to your Twill form, which is then captured and saved into its own dedicated database table. This keeps your main model's table clean while still providing a seamless editing experience.

Key features:

  • Custom Twill Form fieldset: ready-to-use fieldset that includes a custom form field that allows for both manual entry and AI-powered generation of geo-structured data.
  • Frontend Component: Includes a ready-to-use Blade component for outputting the saved data as JSON-LD in your frontend templates.

Requirements

  • PHP: ^8.1
  • Laravel (Illuminate/Support): ^10.0
  • Twill: ^3.0

Installation

1. Install package

composer require futuraddb/twill-geo

2. Publish Assets and Config

To use the package, you need to publish the assets:

php artisan vendor:publish --tag=twill-geo-assets

Optionally, you can also publish the configuration file:

php artisan vendor:publish --tag=twill-geo-config

3. Update Twill Assets

After publishing the assets, you need to rebuild Twill's assets:

php artisan twill:build

4. Run Migrations

The package includes a migration for the geo_structured_data table. If you declined running migrations during the twill:build step, run the migrations manually:

php artisan migrate

Setup

1. Configure env variables

Set the TWILL_GEO_OPENAI_API_KEY env variable. Optionally you can also set TWILL_GEO_LLM_MODEL.

2. Configure the Model

Add the HasGeoStructuredData trait to your Twill model:

use futuraddb\TwillGeo\Repositories\Behaviors\HasGeoStructuredData;
use A17\Twill\Models\Model;

class Project extends Model
{
    use HasGeoStructuredData;

    // Optionally override the field name used in Twill's form
    public static function getTwillModelFieldNameForGeoStructuredData(): string
    {
        return 'custom_geo_field_name';
    }
}

3. Configure the Repository

Add the HandleGeoStructuredData trait to your Twill repository:

use futuraddb\TwillGeo\Repositories\Behaviors\HandleGeoStructuredData;

class ProjectRepository extends ModuleRepository
{
    use HandleGeoStructuredData;
}

4. Configure the Controller

Add the Geo fieldset to your Twill controller's getForm method:

use futuraddb\TwillGeo\Helpers\GeoFormFieldset;

public function getForm(TwillModelContract $model): Form
{
    return parent::getForm($model)
        // ... other fieldsets
        ->addFieldset(GeoFormFieldset::getFieldset(translated: true));
}

The getFieldset method accepts two optional arguments:

  • bool $translated (default: false): Whether the field should be translatable.
  • string $fieldLabel (default: 'GEO'): The label for the fieldset.

Usage

Displaying Structured Data in Frontend

To output the structured data in your layout, use the provided Blade component:

<x-twill-geo::snippet :item="$item ?? null" />

This component will automatically retrieve the geo-structured data from the given item and output it as a <script type="application/ld+json"> tag.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固