Prerequisites

Before you start, make sure you:

Download the latest build extension/driver binary you can see at Release page. It's available for:

Now, LibSQL class is available in your PHP environment! You can use it everywhere in your PHP project 🎉

1

Configure database credentials

Get the database URL:

turso db show --url <database-name>

Get the database authentication token:

turso db tokens create <database-name>

Assign credentials to the environment variables inside .env.

DB_SYNC_URL=
DB_AUTH_TOKEN=
Save this later when you need to connect to Remote and Embedded Replica
2

Create Laravel Project

Using Composer:

composer create-project laravel/laravel turso-laravel

If you already have laravel installer:

laravel new turso-laravel
3

Install Turso Driver Laravel

Install turso-driver-laravel:

composer require tursodatabase/turso-driver-laravel

Add this LibSQLServiceProvider class at bootstrap/providers.php:

Turso\Driver\Laravel\LibSQLDriverServiceProvider::class
4

Configure database connection

Setup the environment variable in your Laravel application, choose what the type connection you need.

Other environment variables (Embedded Replica Only)

5

Database configuration

Add this configuration at config/database.php inside the connections array:

'libsql' => [
    'driver' => 'libsql',
    'url' => env('DB_DATABASE', 'database.sqlite'),
    'authToken' => env('DB_AUTH_TOKEN', ''),
    'syncUrl' => env('DB_SYNC_URL', ''),
    'syncInterval' => env('DB_SYNC_INTERVAL', 5),
    'read_your_writes' => env('DB_READ_YOUR_WRITES', true),
    'encryptionKey' => env('DB_ENCRYPTION_KEY', ''),
    'remoteOnly' => env('DB_REMOTE_ONLY', false),
    'database' => null,
    'prefix' => '',
],
Copy and Paste and do not change it! Or try to change it and will broke your app or give you malfunction.
6

Create database seeders

In fresh Laravel installation, your can open file database/seeders/DatabaseSeeder.php and change the code with this:

<?php

namespace Database\Seeders;

use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
    * Seed the application's database.
    */
    public function run(): void
    {
        // We will create 10 fake users
        User::factory(10)->create();
    }
}

then create the database seeders:

php artisan db:seed --class=DatabaseSeeder
7

Execute Query

Examples