adjustsquare/glide-integration

Laravel package for bi-directional integration with GlideApps

dev-main 2025-05-23 05:17 UTC

This package is not auto-updated.

Last update: 2025-05-23 14:49:47 UTC


README

A comprehensive Laravel package for bi-directional integration with GlideApps, providing seamless data synchronization between your Laravel application and Glide tables.

Features

  • Bi-directional Sync: Automatically sync data between Laravel models and Glide tables
  • Queue Support: All sync operations are queued for better performance
  • Webhook Integration: Handle real-time updates from Glide
  • Flexible Mapping: Configure custom field mappings between models and Glide tables
  • Logging: Track all sync operations with detailed logs
  • Artisan Commands: Manage mappings and trigger syncs via CLI
  • Facade Support: Easy-to-use API through Laravel facade

Installation

  1. Add the package to your Laravel project:
composer require adjustsquare/glide-integration
  1. Publish the configuration and migrations:
php artisan vendor:publish --tag=glide-config
php artisan vendor:publish --tag=glide-migrations
  1. Run the migrations:
php artisan migrate
  1. Configure your environment variables:
GLIDE_API_KEY=your-api-key
GLIDE_APP_ID=your-app-id
GLIDE_WEBHOOK_SECRET=your-webhook-secret

Configuration

Edit config/glide.php to configure your model mappings:

'mappings' => [
    \App\Models\User::class => [
        'table_id' => 'your-glide-users-table-id',
        'mapper' => \App\Mappers\UserGlideMapper::class, // optional
    ],
],

Usage

Making a Model Syncable

  1. Implement the GlideSyncable interface:
<?php

namespace App\Models;

use GlideIntegration\Contracts\GlideSyncable;
use GlideIntegration\Traits\HasGlideSync;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements GlideSyncable
{
    use HasGlideSync;

    protected $fillable = [
        'name',
        'email',
        'password',
        'glide_row_id', // Add this field to your migration
    ];

    public function toGlideArray(): array
    {
        return [
            'Name' => $this->name,
            'Email' => $this->email,
            'CreatedAt' => $this->created_at->toDateTimeString(),
            'UpdatedAt' => $this->updated_at->toDateTimeString(),
            'IsActive' => $this->is_active ? 1 : 0,
        ];
    }

    public function fillFromGlide(array $data): void
    {
        $this->fill([
            'name' => $data['Name'] ?? '',
            'email' => $data['Email'] ?? '',
            'is_active' => ($data['IsActive'] ?? 0) == 1,
        ]);
    }
}
  1. Add the glide_row_id field to your model's migration:
Schema::table('users', function (Blueprint $table) {
    $table->string('glide_row_id')->nullable()->index();
});

Manual Sync Operations

Use the Glide facade for manual operations:

use GlideIntegration\Facades\Glide;

// Create a row in Glide
$user = User::find(1);
Glide::createRow($user);

// Update a row in Glide
Glide::updateRow($user);

// Delete a row from Glide
Glide::deleteRow($user);

// Query Glide table
$rows = Glide::queryTable('your-table-id', ['Name' => 'John'], 100, 0);

Artisan Commands

# Sync all records of a model
php artisan glide:sync "App\Models\User"

# Sync a specific record
php artisan glide:sync "App\Models\User" --id=123

# Manage mappings
php artisan glide:mapping create --model="App\Models\User" --table="your-table-id"
php artisan glide:mapping list
php artisan glide:mapping delete --model="App\Models\User"

Webhook Configuration

The package automatically registers a webhook endpoint at /api/glide/webhook. Configure this URL in your Glide app settings.

Custom Mappers

Create custom mappers for complex transformations:

<?php

namespace App\Mappers;

use GlideIntegration\Contracts\GlideMapper;

class UserGlideMapper implements GlideMapper
{
    public function toGlide($model): array
    {
        return [
            'Name' => $model->full_name,
            'Email' => strtolower($model->email),
            'Status' => $model->is_active ? 'Active' : 'Inactive',
        ];
    }
    
    public function fromGlide(array $data): array
    {
        return [
            'full_name' => $data['Name'] ?? '',
            'email' => $data['Email'] ?? '',
            'is_active' => ($data['Status'] ?? '') === 'Active',
        ];
    }
}

Queue Configuration

By default, all sync operations are queued. Configure the queue settings in your .env:

GLIDE_QUEUE_CONNECTION=redis
GLIDE_QUEUE=glide-sync
GLIDE_SYNC_BATCH_SIZE=100
GLIDE_RETRY_ATTEMPTS=3
GLIDE_RETRY_DELAY=60

Logging

Sync operations are logged to the glide_sync_logs table. You can query these logs:

use GlideIntegration\Models\GlideSyncLog;

// Get all sync logs for a model
$logs = GlideSyncLog::where('syncable_type', User::class)
    ->where('syncable_id', $userId)
    ->latest()
    ->get();

// Get failed syncs
$failedSyncs = GlideSyncLog::where('status', 'failed')->get();

Advanced Usage

Conditional Syncing

Override the shouldSyncToGlide method to control when a model syncs:

public function shouldSyncToGlide(): bool
{
    return $this->is_active && $this->email_verified_at !== null;
}

Batch Operations

For large datasets, use the sync command with chunking:

php artisan glide:sync "App\Models\User" --action=sync

Troubleshooting

  1. API Key Issues: Ensure your API key has the necessary permissions
  2. Webhook Failures: Check the webhook secret and signature verification
  3. Queue Issues: Ensure your queue workers are running
  4. Mapping Errors: Verify table IDs and field names match your Glide app

License

This package is open-sourced software licensed under the MIT license.# glide-integration