DEV Community

Cover image for Day 5: Use Supabase with Laravel
Ehtesham Ali
Ehtesham Ali

Posted on

Day 5: Use Supabase with Laravel

Learn how to connect a Laravel project to a Supabase Postgres database and configure user authentication seamlessly.

1. Create a Laravel Project

Ensure PHP and Composer are up to date, then scaffold your Laravel project:

composer create-project laravel/laravel example-app  
Enter fullscreen mode Exit fullscreen mode

2. Install Authentication Template

Set up Laravel Breeze for user authentication:

composer require laravel/breeze --dev  
php artisan breeze:install    
Enter fullscreen mode Exit fullscreen mode

3. Configure Postgres Connection

  • Create a new Supabase project at database.new. Note if account not created will display:

Supabase Account

Other wise will display this:

Create New Project

  • Copy the URI connection string.

Note to get connection string click on connect button:

Connect Button

  • Replace password with your database password. Update .env:
DB_CONNECTION=pgsql  
DATABASE_URL=postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:5432/postgres  
Enter fullscreen mode Exit fullscreen mode

4. Change Default Schema

Modify search_path in app/config/database.php to avoid using the public schema (default for Supabase's API):

'pgsql' => [
    'driver' => 'pgsql',
    '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,
    'search_path' => 'laravel',
    'sslmode' => 'prefer',
],
Enter fullscreen mode Exit fullscreen mode

5. Run Migrations

Set up the required authentication tables:

php artisan migrate  
Enter fullscreen mode Exit fullscreen mode

6. Start the App

Run the development server and test user registration and login:

php artisan serve  
Enter fullscreen mode Exit fullscreen mode

Access your app at http://127.0.0.1:8000.

That's it! Your Laravel app is now connected to Supabase, ready for development.

Celebration Gif

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay