In this Laravel quickstart we will learn how to:

  • Install the Turso Laravel adapter
  • Configure Laravel to use Turso
  • Create a model and migration
  • Perform CRUD operations using Eloquent
1

Retrieve database credentials

You will need an existing database to continue. If you don’t have one, create one.

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.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
You will want to store these as environment variables.
2

Install

Install the package to your Laravel project using Composer:

composer require turso/libsql-laravel
Make sure to enable FFI in your PHP configuration to use the Laravel adapter.
3

Configure

Choose your preferred setup and configure accordingly:

4

Create a model and migration

Create a User model and migration:

php artisan make:model User -m

Update the migration file:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamps();
    });
}
5

Run migrations

Apply the migration to create the users table:

php artisan migrate
6

Execute CRUD operations

Now you can perform CRUD operations using Eloquent: