# 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.

## Service providers

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.

## Container bindings

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.

```php
use SurrealDB\SDK\Surreal;

$client = app(Surreal::class);
```

## Facades

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

### `SurrealDB`

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

| Method | Description |
|--------|-------------|
| `run($surql, $bindings, $connection?)` | Run raw SurrealQL |
| `query($query, $connection?)` | Run a [`BoundQuery`](/docs/reference/php/v2/api/utilities.md#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](/docs/reference/php/frameworks/laravel/testing.md) helpers |

```php
use SurrealDB\Laravel\Facades\SurrealDB;

SurrealDB::health();

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

### `Surreal`

Resolves the underlying SDK [`Surreal`](/docs/reference/php/v2/api/core.md) client for direct, lower-level access.

```php
use SurrealDB\Laravel\Facades\Surreal;

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

### `Surqlize`

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

| Method | Description |
|--------|-------------|
| `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](/docs/reference/php/frameworks/laravel/queries-and-transactions.md#transactions) |

```php
use SurrealDB\Laravel\Facades\Surqlize;

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

## Learn more

- [Configuration](/docs/reference/php/frameworks/laravel/configuration.md) for the settings these bindings read
- [Queries and transactions](/docs/reference/php/frameworks/laravel/queries-and-transactions.md) for using the facades
- [Testing](/docs/reference/php/frameworks/laravel/testing.md) for the fake executor
