• Start

Languages

/

PHP

/

Frameworks

/

Laravel

Container and facades

The service providers, container bindings, and the SurrealDB, Surreal, and Surqlize facades the Laravel integration registers.

The integration registers two service providers, binds the SDK and ORM into the container, and exposes three facades.

Laravel auto-discovers both providers.

  • SurrealDB\Laravel\SurrealDBServiceProvider owns the SDK configuration, client construction, and the surrealdb container alias.

  • SurrealDB\Laravel\SurqlizeServiceProvider owns the ORM configuration, the schema commands, Surqlize's executor binding, and ConnectionManager setup.

The SDK provider binds:

  • SurrealDB\SDK\Surreal and the surrealdb alias for the raw SDK client.

  • SurrealDB\Laravel\SurrealDBManager plus the surrealdb.manager and surrealdb.connection aliases for the Laravel lifecycle helpers.

The ORM provider binds:

  • SurrealDB\SDK\Contracts\QueryExecutor for Surqlize query execution.

  • Surqlize\Model\SchemaManager for schema definitions and application.

  • SurrealDB\Laravel\SurqlizeManager and the surqlize alias for the Laravel-friendly ORM helpers.

The ORM provider also registers Surqlize's global ConnectionManager with a lazy executor that resolves the configured surqlize.executor binding only when a query runs. By default that points at surrealdb.connection, so model queries use the Laravel-managed connection and connect lazily.

use SurrealDB\SDK\Surreal;

$client = app(Surreal::class);

The integration ships three facades in the SurrealDB\Laravel\Facades namespace.

The manager facade. It manages named connections, runs SurrealQL, and exposes lifecycle and testing helpers. Most methods take an optional connection name.

MethodDescription
run($surql, $bindings, $connection?)Run raw SurrealQL
query($query, $connection?)Run a BoundQuery
client($name?) / connection($name?)Resolve the SDK client or its controller
connect() / disconnect() / reconnect() / isConnected()Manage the connection lifecycle
health() / version()Check the server
using($connection)Get an executor scoped to a connection
fake() / assertSurrealQuerySent() / resetFakes()Testing helpers
use SurrealDB\Laravel\Facades\SurrealDB;

SurrealDB::health();

$result = SurrealDB::run('RETURN $message', ['message' => 'hello']);

Resolves the underlying SDK Surreal client for direct, lower-level access.

use SurrealDB\Laravel\Facades\Surreal;

$result = Surreal::run('RETURN true;');

Exposes the ORM manager: the executor, schema helpers, and transactions.

MethodDescription
executor()The configured Surqlize executor
schemaDefinitions($models?)The schema statements for the models
applySchema($models?, $executor?)Apply the schema
transaction($callback, $executor?, $connection?)Run a transaction
use SurrealDB\Laravel\Facades\Surqlize;

Surqlize::transaction(function ($transaction): void {
User::createQuery(['name' => 'beau'], executor: $transaction)->execute();
});

Was this page helpful?