In Laravel you query SurrealDB three ways: through Surqlize models, through the raw SDK client, and through the SurrealDB manager facade. The integration registers the executor, so model queries work without passing one.
Model queries
Define Surqlize models and query them directly. They run through the Laravel-managed connection.
$users = User::select(fn ($user) => [$user->id, $user->name])
->where(fn ($user) => $user->name->eq('beau'))
->collectModels();
$user = User::create(['name' => 'Tobie', 'age' => 32], id: 'tobie');See Querying and Mutations for the full model API.
Raw SDK access
Resolve the SDK client for lower-level access.
use SurrealDB\SDK\Surreal;
$result = app(Surreal::class)->run('RETURN $message', ['message' => 'hello']);The manager facade
The SurrealDB facade runs SurrealQL with lifecycle helpers around the same client, and targets a named connection with the connection: argument.
use SurrealDB\Laravel\Facades\SurrealDB;
SurrealDB::health();
$result = SurrealDB::run('RETURN $message', ['message' => 'hello']);
$analytics = SurrealDB::run(
'RETURN $message',
['message' => 'hello'],
connection: 'analytics',
);Transactions
The Surqlize facade runs a transaction over the executor. Run each query inside the callback through the transaction it passes you, with the executor: argument or withExecutor(). The transaction commits when the callback returns and rolls back if it throws.
use SurrealDB\Laravel\Facades\Surqlize;
Surqlize::transaction(function ($transaction): void {
User::createQuery(['name' => 'beau'], executor: $transaction)->execute();
});
Surqlize::transaction(
fn ($transaction) => User::createQuery(['name' => 'beau'], executor: $transaction)->execute(),
connection: 'analytics',
); Surqlize::transaction() uses Surqlize's executor-based SurrealQL transaction batching. SDK-native transaction ids are not exposed through the Laravel facade yet, because they depend on the WebSocket transport and server feature support.
Learn more
Container and facades for the facade method reference
Surqlize transactions for the batching mechanism
Testing for asserting the queries your code sends