bdevs / supabase-laravel
Laravel package for integrating with Supabase (Auth, Storage, Edge Functions).
v0.1.0
2026-09-09 14:27 UTC
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.8|^8.0
- illuminate/auth: ^11.0|^12.0|^13.0
- illuminate/broadcasting: ^11.0|^12.0|^13.0
- illuminate/bus: ^11.0|^12.0|^13.0
- illuminate/cache: ^11.0|^12.0|^13.0
- illuminate/contracts: ^11.0|^12.0|^13.0
- illuminate/events: ^11.0|^12.0|^13.0
- illuminate/filesystem: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/notifications: ^11.0|^12.0|^13.0
- illuminate/queue: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- illuminate/validation: ^11.0|^12.0|^13.0
- laravel/prompts: ^0.1|^0.2|^0.3
- laravel/serializable-closure: ^1.3|^2.0
- league/flysystem: ^3.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Laravel package for talking to a Supabase project's REST API (PostgREST), with support for service-role, user-authenticated, and anonymous request contexts.
Features
- Multiple auth contexts —
serviceRole()(bypasses RLS),asUser($token)(acts as a specific user, respects RLS),anonymous()(anon key, respects RLS). - Multiple named connections — configure more than one Supabase project/environment in
config/supabase.php. - Fluent PostgREST query builder (
Supabase::table(...)):select()with column listsinsert(),update(),upsert()(withonConflict),delete()where()raw escape hatch plus typed filters:eq,neq,gt,gte,lt,lte,in,is,like,ilike,containsorWhere()for OR-grouped conditionsorderBy(),limit(),offset()get()→Collection,single()→ array (throws unless exactly one row),maybeSingle()→ array|nullpaginate()usingPrefer: count=exact+Content-Range, returning data + page metadata
- RPC support — call Postgres functions exposed via PostgREST with
Supabase::rpc(). - Realtime:
Supabase::channel($topic)->broadcast($event, $payload)— send broadcast messages from PHP over plain HTTP- A
supabaseLaravel Broadcasting driver, soevent(new SomethingHappened)/ShouldBroadcastwork unmodified, reusingroutes/channels.phpauthorization resources/js/lib/supabase-realtime.ts— browser-side subscribe/unsubscribe lifecycle, Postgres change events (insert/update/delete filters), broadcast receive, and presence (track/untrack/sync/join/leave), via@supabase/supabase-js
- Laravel integration:
- Events —
UserSignedUp,UserSignedIn,UserSignedOut,FileUploaded,FileDeleted - Gates/Policies —
SupabaseUser::role()/roles()/hasRole()/hasAnyRole()read straight from verified JWT claims - Queue —
CallSupabase::dispatch(fn () => ...), aShouldQueuewrapper for any Supabase call - Notifications —
SupabaseChanneldelivers notifications as a Realtime broadcast - Cache —
Cache::store('supabase'), aStoreimplementation backed by a Postgres table via PostgREST - Validation —
SupabaseUnique, aRule::unique()equivalent that checks a Supabase table
- Events —
- Typed exceptions —
SupabaseException/SupabasePostgrestException/SupabaseRealtimeExceptionexpose->status()and->body()from the failed response. - Built-in HTTP resilience — configurable timeout and retry (
config('supabase.http')). - Developer experience:
php artisan supabase:install— interactive.env+ config setupphp artisan supabase:test— PostgREST/Auth/Storage connectivity health check, CI-friendly exit codephp artisan supabase:make-function {name}— scaffold a.sqlfile for a Postgres RPC functionphp artisan supabase:push-functions— push changed.sqlfunction files directly to Postgres viadb_url, skipping unchanged onesphp artisan supabase:rollback-function {function}— restore a function's previously pushed versionphp artisan supabase:make-table {name}— scaffold a timestamped.sqlmigration file (Laravel migration naming), with-- up/-- downsectionsphp artisan supabase:migrate {table?}— run pending table migrations in order, tracked by filename and batch (likephp artisan migrate)php artisan supabase:rollback-table {name?}— reverse the last migration batch, or a single named migration, using its-- downsection (likephp artisan migrate:rollback)php artisan supabase:make-seeder {name}— scaffold a PHP class seeder (via theSupabasefacade/PostgREST);--sqlscaffolds a raw-SQL seeder viadb_urlinsteadphp artisan supabase:seed {name?}— run seeders (likephp artisan db:seed); re-runnable, not tracked as "applied"- Structured, correlated (
request_id+duration_ms) request/response logging with automatic redaction of passwords/tokens/api keys, gated behindSUPABASE_LOG_ENABLED/SUPABASE_DEBUG - Config publishing via
php artisan vendor:publish --tag=supabase-config
- Self-contained test suite (Orchestra Testbench + Pest) shipped with the package.
Documentation
- Installation & Configuration — setup,
.env, auth contexts - Query Builder — select/insert/update/upsert/delete, pagination, single-row helpers
- Filters —
eq,in,like,contains,orWhere, etc. - RPC & Errors — calling Postgres functions, exception handling
- Storage — upload/download/delete/move/copy/list, public/signed URLs, bucket management
- Realtime — channels, broadcast, Postgres change events, presence, subscribe/unsubscribe, the Laravel Broadcasting bridge
- Laravel Integration — events, Gates/Policies, queue, notifications, cache, validation
- Developer Experience — artisan commands, config publishing, debug mode, structured logging
- Testing — running and writing tests for this package
Quick example
use BlackDevs\SupabaseLaravel\Facades\Supabase; $users = Supabase::table('users') ->select('id,name,email') ->eq('active', true) ->gte('age', 18) ->orderBy('name') ->limit(10) ->get();
See docs/installation.md to get started.