承接 prahsys/laravel-supabase 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

prahsys/laravel-supabase

Composer 安装命令:

composer require prahsys/laravel-supabase

包简介

A Laravel 12+ package for seamless integration with Supabase, including UUID handling and database features

README 文档

README

A Laravel package for seamless integration with Supabase, providing PostgreSQL-specific features for Laravel applications.

Development

This package can be developed locally within a Laravel application. The main project includes tooling to easily switch between local development and remote package installations.

Working with Local Package Development

To switch between developing locally and using the published package:

  1. Use local development version:

    composer packages:dev-mode
    composer update prahsys/laravel-supabase --prefer-source
  2. Use remote published version:

    composer packages:deploy-mode
    composer update prahsys/laravel-supabase

The local development mode creates a symlink to the package in the packages/ directory, allowing you to make changes directly to the package code while testing in your application.

Features

Supabase Database Driver

The package registers a dedicated supabase database driver that you can use in your Laravel database configuration. This driver extends the default PostgreSQL driver with automatic handling of UUID columns in:

  • Where clauses
  • Join conditions
  • WhereIn statements

The driver works in two ways:

  1. It automatically detects common UUID column patterns (like 'id', '*_id', etc.)
  2. It works with the CastsUuidColumns trait to allow explicit UUID column definition

UUID Handling in Supabase

When working with UUIDs in Supabase, comparing a UUID column with a string value requires explicit casting. This is especially important because Supabase doesn't allow creating global implicit casts or custom operators that would normally solve this issue in a standard PostgreSQL installation.

-- This fails in Supabase:
SELECT * FROM users WHERE id = '123e4567-e89b-12d3-a456-426614174000';

-- This works:
SELECT * FROM users WHERE CAST(id AS TEXT) = '123e4567-e89b-12d3-a456-426614174000';

With the Supabase driver, these casts are applied automatically, so you can write normal Laravel queries:

// These work automatically with the Supabase driver
$user = User::find($uuidString);
$user = User::where('id', $uuidString)->first();
$users = User::whereIn('id', [$uuid1, $uuid2])->get();

// Joins also work automatically
$posts = Post::join('users', 'posts.user_id', '=', 'users.id')
    ->where('users.email', 'test@example.com')
    ->get();

Explicit UUID Column Definition

For more precise control, you can use the CastsUuidColumns trait to explicitly define UUID columns in your models:

use Prahsys\Supabase\Traits\CastsUuidColumns;

class Post extends Model
{
    use CastsUuidColumns;
    
    // Define additional UUID columns beyond the primary key
    protected $uuidColumns = [
        'user_id',
        'other_uuid_column',
    ];
}

The trait:

  1. Automatically includes the primary key as a UUID column
  2. Adds any columns specified in the $uuidColumns property
  3. Communicates this information to the query builder for proper UUID handling

Custom UUID Column Detection

For advanced use cases, you can also register a custom UUID column detector function:

use Prahsys\Supabase\Database\Query\Grammars\PostgresGrammar;

// In a service provider or bootstrap file
PostgresGrammar::detectUuidColumnsWith(function ($columnName, $query) {
    // Your custom logic to determine if a column is a UUID
    // For example, use a specific naming pattern or check against a list
    return str_contains($columnName, 'uuid_') || in_array($columnName, ['custom_uuid_field']);
});

This allows for full customization of UUID column detection beyond the built-in naming conventions.

Installation

composer require prahsys/laravel-supabase

Database Configuration

You can use the custom supabase driver in your config/database.php:

'connections' => [
    'supabase' => [
        'driver' => 'supabase',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],
    
    // Your other connections...
],

The supabase driver is a PostgreSQL driver with additional configurations optimized for Supabase, so you can use it just like the standard pgsql driver.

Development and Testing

Running Tests

To run the tests:

composer test

This will run all tests using SQLite in-memory database for speed.

Testing with a Real Supabase Connection

To test with a real Supabase database:

  1. Edit the .env.testing file with your Supabase credentials
  2. Run the special test command:
composer test-supabase

This is useful for verifying PostgreSQL functionality in an actual database environment.

Compatibility

  • Laravel 10.x, 11.x, and 12.x
  • PHP 8.1 and above
  • PostgreSQL databases including Supabase

License

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

prahsys/laravel-supabase 适用场景与选型建议

prahsys/laravel-supabase 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.85k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 prahsys/laravel-supabase 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 prahsys/laravel-supabase 我们能提供哪些服务?
定制开发 / 二次开发

基于 prahsys/laravel-supabase 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-11