Skip to content

EloquentDatabase

First-class adapter for Eloquent (illuminate/database) used standalone via the Capsule Manager.

EloquentDatabase::getConnection() returns the Manager; models (extends Illuminate\Database\Eloquent\Model) work once global/boot_eloquent is enabled.

Configuration parameters (in databases.xml): - connection : inline Eloquent config array, OR the name of another configured database to borrow a live PDO from (layer mode — still requires a driver so Eloquent knows the SQL grammar). Omit for standalone mode using flat params. - driver : mysql | pgsql | sqlite | sqlsrv (required unless an inline connection array supplies it) - host,port,database,username,password,charset,collation,prefix - connection_name : Capsule connection name (default “default”) - global : call setAsGlobal() (default false) - boot_eloquent : call bootEloquent() (default = value of global)

class EloquentDatabase extends AbstractOrmDatabase

ExtendsAbstractOrmDatabase
SourceEloquentDatabase.php
MethodDescription
getCapsule(): ManagerReturns the Capsule manager, connecting on first use.
getEloquentConnection(): ConnectionThe underlying Illuminate connection (query builder, PDO, transactions).
getPdo(): PDOReturns the PDO handle Eloquent is using for the configured connection.
getResource(): mixedReturns the Illuminate connection, routed through EloquentDatabase::getCapsule() so a layer-mode rebind happens before the caller sees it — the base class’s getResource() would otherwise hand back $this->resource directly and skip that check.
ping(): boolProbes the connection with SELECT 1 on the raw PDO handle.
shutdown(): mixedRolls back any open transaction, purges the connection from Eloquent’s database manager and drops the capsule.

public function getCapsule(): Manager

Returns the Capsule manager, connecting on first use.

In layer mode, re-checks the borrowed database’s current PDO on every call and rebinds it into the Illuminate connection if it has changed. The source can rotate its own live handle independently of this adapter — a PropulsionDatabase resolving fresh from Propulsion’s pool on every call, or a PdoDatabase reconnecting after ping() found its old handle dead — and a rotated-away handle often keeps answering queries just fine on its own, so nothing here would notice the divergence without asking the source again.

Returns Manager

ThrowsWhen
DatabaseExceptionIf the capsule could not be built, or the connection is not a Capsule.

public function getEloquentConnection(): Connection

The underlying Illuminate connection (query builder, PDO, transactions).

Returns Connection

public function getPdo(): PDO

Returns the PDO handle Eloquent is using for the configured connection.

In layer mode this is the handle borrowed from another configured database rather than one Eloquent opened itself.

Returns PDO

ThrowsWhen
DatabaseExceptionIf the capsule could not be built.

public function getResource(): mixed

Returns the Illuminate connection, routed through EloquentDatabase::getCapsule() so a layer-mode rebind happens before the caller sees it — the base class’s getResource() would otherwise hand back $this->resource directly and skip that check.

Returns mixed

ThrowsWhen
DatabaseExceptionIf the capsule could not be built.

public function ping(): bool

Probes the connection with SELECT 1 on the raw PDO handle.

Returns true when nothing has been connected yet, since lazy connect handles it on first use. If the query throws, the capsule and resource are cleared so the next getConnection() rebuilds them, and false is returned.

Returns bool

public function shutdown(): mixed

Rolls back any open transaction, purges the connection from Eloquent’s database manager and drops the capsule.

Both steps are attempted independently; a failure in either is logged at warning and does not stop the shutdown. The capsule and resource are cleared regardless.

Returns mixed

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getConnection()DatabaseRetrieve the database connection associated with this Database implementation.
getDatabaseManager()DatabaseRetrieve the Database Manager instance for this implementation.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getName()DatabaseRetrieve the name of this database connection.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()DatabaseInitialize this Database.
removeParameter()ParameterHolderRemove a parameter.
reset()DatabaseReturns this Database to its pre-initialize() state.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
startup()DatabaseDo any necessary startup work after initialization.