How to use supabase with laravel?

Deploying application a lot easier these days, one of the most important component of our Laravel application is database. While managing database is not an easy task there are a lot of company that offer managed database that can help us to save time configuring database. Today we will learn how to use managed database service Supabase with laravel application.

Create Supabase account

Supabase is managed database service powered by PostgreSQL database, supabase offer a lot of feature like row level permission, vector embedding with pgvector and a lot more.

But today we only care about the database, so we are not going to use any of supbase features. To create supabase account is very easy.

You can go to https://supabase.com/dashboard/sign-up, there are two options register with email and password or with your github account.

supabase-signup

Get supabase credentials

After signup now let's create new project, new project means new database. To create new project you can click button new project.

dashboard-supabase

After click new project you will see these form. You can fill the form and make sure to save the database password, we need this to manually connect to our database later.

new-project

Finally you can grab the credentials of your database from Setting > Database page.

setting-page

New laravel project

You can use this in your existing laravel project or new laravel project, if you want to create new project follow this step.

Run laravel new to create project:

laravel new supabase-laravel-example

new-laravel

Don't forget to select postgres database drived.

select-database

And now we can just put that credentials to our .env file. Here's example config.

DB_CONNECTION=pgsql
DB_HOST=db.[...].supabase.co
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=Axx......

Verify setup

The last thing you need to do is to verify your database config by running the migration.

php artisan migrate

If the migration works then you good to go now.