Every Supabase project comes with a full Postgres database, a free and open source database which is considered one of the world's most stable and advanced databases.
Postgres is an ideal choice for your Laravel PHP applications as Laravel ships with a Postgres adapter built in!
In this post we'll start from scratch, creating a new Laravel application, setting up the Laravel Breeze starter kit for user authentication, and connecting it to our Supabase Postgres database.
Need help migrating?
Supabase is one of the best free alternatives to Heroku Postgres. See this guide to learn how to migrate from Heroku to Supabase.
There's also a Heroku to Supabase migration tool available to migrate in just a few clicks.
If you prefer video guide, you can follow along below. And make sure to subscribe to the Supabase YouTube channel!
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.
Install the Authentication template
Install Laravel Breeze, a simple implementation of all of Laravel's authentication features.
Note: this template does not use Supabase Auth but rather Laravel's built in Auth system. This means that Supabase Auth pricing does not apply. You'd only be billed for Database resources used in this case.
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.
Laravel ships with a Postgres adapter out of the box, you can simply configure it via the environment variables. You can find the database URL in your Supabase Dashboard.
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 config/database.php
:
Run the database migrations
Laravel ships with database migration files that set up the required tables for Laravel Authentication and User Management.
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.
Conclusion
Supabase is the ideal platform for powering your Postgres database for your Laravel applications! Every Supabase project comes with a full Postgres database and a good number of useful extension!
Try it out now at database.new!