Home > Backend Development > PHP Tutorial > Day Use Supabase with Laravel

Day Use Supabase with Laravel

Susan Sarandon
Release: 2025-01-02 21:35:44
Original
487 people have browsed it

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  
Copy after login

2. Install Authentication Template

Set up Laravel Breeze for user authentication:

composer require laravel/breeze --dev  
php artisan breeze:install    
Copy after login

3. Configure Postgres Connection

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

Day Use Supabase with Laravel

Other wise will display this:

Day Use Supabase with Laravel

  • Copy the URI connection string.

Note to get connection string click on connect button:

Day Use Supabase with Laravel

  • Replace password with your database password. Update .env:
DB_CONNECTION=pgsql  
DATABASE_URL=postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:5432/postgres  
Copy after login

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',
],
Copy after login

5. Run Migrations

Set up the required authentication tables:

php artisan migrate  
Copy after login

6. Start the App

Run the development server and test user registration and login:

php artisan serve  
Copy after login

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

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

Day Use Supabase with Laravel

The above is the detailed content of Day Use Supabase with Laravel. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template