polarizetech/wixable

自动将 Wix Headless CMS 的数据收集项导入到您的 Laravel 模型中

0.0.3 2024-04-13 21:08 UTC

This package is auto-updated.

Last update: 2024-09-17 20:12:43 UTC


README

Wixable

自动将(单向同步从 Wix CMS)数据项从 Wix Headless CMS 导入到您的应用程序数据库中。

安装

安装包: composer require polarize/wixable

将您的 Wix API 凭据添加到环境文件中

WIX_API_KEY="..."
WIX_ACCOUNT_ID="..."
WIX_SITE_ID="..."

发布 Wixables "wixable_data_items" 表的迁移: php artisan vendor:publish --tag=wixable.migrations

运行迁移: php artisan migrate

设置您的模型

在您的 app/Models 文件夹中添加一个新类,该类扩展 Wixable\Wixable。对于您希望同步的每个 Wix 中的 数据收集,重复此步骤(模型名称应该是数据收集 ID 的单数形式)。

例如,在 Wix 中我的 "Breakfast Sandwich Reviews" 收集(可能具有 数据收集 ID 为 "BreakfastSandwichReviews")的情况下,我会这样做

  1. 运行 artisan make 命令: php artisan make:model BreakfastSandwichReview

  2. 更新新模型以扩展 Wixable\Wixable 抽象类

<?php

namespace App\Models;

use Wixable\Wixable;

class BreakfastSandwichReview extends Wixable
{
    //
}

注意:您还可以通过 $dataCollectionId 属性设置数据收集名称,如下所示...

class Reviews extends Wixable
{
    protected string $wixDataCollection = 'BreakfastSandwichReviews';

    ...

安排导入器

要自动导入您的 Wix 数据项,请将以下行添加到您的 AppServiceProvider(或者如果您愿意,可以以其他方式安排 php artisan wixable:import 命令)。

use Illuminate\Support\Facades\Schedule;

public function boot()
{
    Schedule::command('wixable:import')->everyFiveMinutes();

    ...