iclimber / laravel-supabase-flysystem

Supabase 驱动器用于 Laravel Flysystem 存储

1.0.1 2024-09-04 09:22 UTC

This package is auto-updated.

Last update: 2024-09-04 09:29:28 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

使用此 Flysystem 适配器,轻松将 Supabase 集成到 Laravel 作为存储驱动程序。

使用 Laravel 方便的存储系统简化文件存储和检索,同时利用 Supabase 的强大功能。

要求

  • PHP >= 8.1
  • Laravel 10.x|11.x
  • Fileinfo ext-fileinfo

安装

要安装此包,请使用 Composer

composer require quix-labs/laravel-supabase-flysystem

配置

安装后,在 Laravel 的 config/filesystems.php 中配置 Supabase 驱动程序。

将以下内容添加到 disks 数组中

'supabase' => [
    'driver' => 'supabase',
    'key'    => env('SUPABASE_STORAGE_KEY'), // Use a privileged key; read-only does not work
    'bucket' => env('SUPABASE_STORAGE_BUCKET'),
    'endpoint' => env('SUPABASE_STORAGE_ENDPOINT'),

    'url'      => null, // <- Automatically generated; change here if you are using a proxy

    'public'                      => true,  // Default to true
    'defaultUrlGeneration'        => null, // 'signed' | 'public' <- default depends on public

    'defaultUrlGenerationOptions' => [
        'download'  => false,
        'transform' => [],
    ],

    'signedUrlExpires' => 60*60*24, // 1 day <- default to 1 hour (3600)
],

用法

// Example code for using the Supabase driver with Laravel Storage
Storage::disk('supabase')->put('file.txt', 'contents');

// Custom function to generate a public URL
Storage::disk('supabase')->getAdapter()->getPublicUrl('completelyPublicFile.png', [
    'download'  => false, // Set this to true if you want the user's browser to automatically trigger download
    
    // Transform only applied if the file is detected as an image; else ignored
    'transform' => [ 
        'width' => 200,
        //... All options -> https://supabase.com/docs/guides/storage/serving/image-transformations#transformation-options
    ]]);

// Custom function to generate a signed URL
Storage::disk('supabase')->getAdapter()->getSignedUrl('veryConfidentialFile.png', [
    'expiresIn' => 60 * 5, // 5 minutes
    //... Same options as getPublicUrl
]);

变更日志

请参阅 CHANGELOG 了解最近的变化。

致谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。