PHP code example of prahsys / laravel-supabase

1. Go to this page and download the library: Download prahsys/laravel-supabase library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prahsys / laravel-supabase example snippets


// 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', '[email protected]')
    ->get();

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',
    ];
}

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']);
});

'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...
],