Getting Started

Framework Quickstarts

Use Supabase with Laravel

Learn how to create a PHP Laravel project, connect it to your Supabase Postgres database, and configure user authentication.

1

Create a Laravel Project

Make sure your PHP and Composer versions are up to date, then use composer create-project to scaffold a new Laravel project.

See the Laravel docs for more details.

Terminal

_10
composer create-project laravel/laravel example-app

2

Install the Authentication template

Install Laravel Breeze, a simple implementation of all of Laravel's authentication features.

Terminal

_10
composer require laravel/breeze --dev
_10
php artisan breeze:install

3

Set up the Postgres connection details

Go to database.new and create a new Supabase project. Save your database password securely.

When your project is up and running, navigate to the database settings to find the URI connection string. Make sure Use connection pooling is checked and Session mode is selected. Then copy the URI. Replace the password placeholder with your saved database password.

.env

_10
DB_CONNECTION=pgsql
_10
DATABASE_URL=postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:5432/postgres

4

Change the default schema

By default Laravel uses the public schema. We recommend changing this as supabase exposes the public schema as a data API.

You can change the schema of your Laravel application by modifying the search_path variable app/config/database.php.

app/config/database.php

_14
'pgsql' => [
_14
'driver' => 'pgsql',
_14
'url' => env('DATABASE_URL'),
_14
'host' => env('DB_HOST', '127.0.0.1'),
_14
'port' => env('DB_PORT', '5432'),
_14
'database' => env('DB_DATABASE', 'forge'),
_14
'username' => env('DB_USERNAME', 'forge'),
_14
'password' => env('DB_PASSWORD', ''),
_14
'charset' => 'utf8',
_14
'prefix' => '',
_14
'prefix_indexes' => true,
_14
'search_path' => 'laravel',
_14
'sslmode' => 'prefer',
_14
],

5

Run the database migrations

Laravel ships with database migration files that set up the required tables for Laravel Authentication and User Management.

Note: Laravel does not use Supabase Auth but rather implements its own authentication system!

Terminal

_10
php artisan migrate

6

Start the app

Run the development server. Go to http://127.0.0.1:8000 in a browser to see your application. You can also navigate to http://127.0.0.1:8000/register and http://127.0.0.1:8000/login to register and log in users.

Terminal

_10
php artisan serve