PHPackages                             symbiotic/eloquent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. symbiotic/eloquent

ActiveLibrary[Database &amp; ORM](/categories/database)

symbiotic/eloquent
==================

Inherited model and encapsulated connection manager to avoid conflicts with Laravel

1.4.2(3y ago)024BSD-3-ClausePHPPHP &gt;=8.0

Since Mar 12Pushed 3y agoCompare

[ Source](https://github.com/symbiotic-php/eloquent)[ Packagist](https://packagist.org/packages/symbiotic/eloquent)[ RSS](/packages/symbiotic-eloquent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Symbiotic (Laravel Eloquent)
============================

[](#symbiotic-laravel-eloquent)

README.RU.md [РУССКОЕ ОПИСАНИЕ](https://github.com/symbiotic-php/eloquent/blob/master/README.RU.md)

**Eloquent wrapper package (`laravel/database`) for parallel independent work with Laravel models of separate applications.**

Installation
------------

[](#installation)

```
composer require symbiotic/eloquent

```

Description
-----------

[](#description)

Configuration conflicts occur when third-party functionality using the `laravel/database` package works together connections. The current package inherits the model and manager class, which allows you to work in parallel with Laravel to several independent libraries with their own connection settings and use Laravel models. It is also possible to configure connections by basic namespaces, this makes it possible for each packet to specify its own connection.

### Usage

[](#usage)

Manager initialization

```
  $config = [
       'default' => 'my_connect_name',
        // Connections by package namespaces
        'namespaces' => [
           '\\Modules\\Articles' => 'mysql_dev',
        ]
       'connections' => [
            'my_connect_name' => [
                'driver' => 'mysql',
                'database' => 'database',
                'username' => 'root',
                'password' => 'toor',
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
            ],
            'mysql_dev' => [
             // ....
            ],
        ]
    ];

  // Building from an array of data {@link https://github.com/symbiotic-php/database}
  $connectionsConfig = \Symbiotic\Database\DatabaseManager::fromArray($config);

  // Manager initialization
  $manager = new \Symbiotic\Database\Eloquent\EloquentManager(
        $connectionsConfig,
        \Symbiotic\Database\Eloquent\SymbioticModel::class // Base model class
        // If you are using Laravel models -  \Illuminate\Database\Eloquent\Model::class
        );

  // Additionally, you can install the Event Manager (\Illuminate\Contracts\Events\Dispatcher)
  $manager->setEventDispatcher(new Dispatcher());

  // Activating your connection manager for models
  $manager->bootEloquent();

  // Your code and requests....

  // Extracting the current connection manager and installing the previous one (if any)
  $manager->popEloquent();
```

When you initialize the Laravel base model `\Illuminate\Database\Eloquent\Model::class` you will globally overwrite the manager connections in all descendants of the model, so be sure to check out your connection manager after your functionality is finished. You can use the inherited model `\Symbiotic\Database\Eloquent\SymbioticModel::class` as a base, it eliminates all configuration conflicts.

It is recommended to inherit from the SymbioticModel class:

```
use Symbiotic\Database\Eloquent\SymbioticModel;

class User extends SymbioticModel
{
    //....
}
```

### Basic Methods

[](#basic-methods)

```
/**
* @var  \Symbiotic\Database\Eloquent\EloquentManager $manager
 */
// Returns the Laravel connection manager {@see \Illuminate\Database\DatabaseManager}
$laravelDatabase = $manager->getDatabaseManager();

// Getting a Connection Object {@see \Illuminate\Database\Connection}
// if called without a parameter, it will return the connection 'default'
$connection = $manager->getConnection($connectionName ?? null);

// Adding a connection
$manager->addConnection(
         [
            'driver' => 'mysql',
            'database' => 'test_db',
            'username' => 'root',
            'password' => 'toor',
            //....
        ],
        'test_connection'
);
// Installing an Event Dispatcher for Models {@uses \Illuminate\Contracts\Events\Dispatcher}
$manager->setEventDispatcher($dispatcher);

// Getting the event dispatcher, if the dispatcher is not set, will return the anonymous class NullDispatcher
$dispatcher = $manager->getEventDispatcher();

// Force model connection switching at runtime
 $manager->withConnection('connection_name', function() {
    $model = new MyModel();
    $model->save([]);
 });
```

### Configuring connections depending on model namespaces

[](#configuring-connections-depending-on-model-namespaces)

Sometimes some independent functionality needs to be placed in a separate database, To do this, you can use the connection configuration by namespaces.

```
/**
 * @var  \Symbiotic\Database\Eloquent\EloquentManager $manager
 * @var  \Symbiotic\Database\DatabaseManager $symbioticDatabase
 */
// Returns the Symbiotic connection manager {@see \Symbiotic\Database\DatabaseManager}
// Read the documentation of the manager and the features of his behavior {@link https://github.com/symbiotic-php/database}
$symbioticDatabase = $manager->getSymbioticDatabaseManager();

// Is the connection search by namespace active?
$bool = $symbioticDatabase->isActiveNamespaceFinder();

// Enable/disable search by namespaces
$symbioticDatabase->activateNamespaceFinder(false);

// Adding a separate connection for a module
$symbioticDatabase->addNamespaceConnection('\\Modules\\PagesApplication', 'test_connection');

// Getting the name of the connection by class, if disabled, it will return null
$pagesConnectionName = $symbioticDatabase->getNamespaceConnection(\Modules\PagesApplication\Models\Event::class); // return `test_connection`

// Automatic search for a connection along the call stack via debug_backtrace, if disabled, returns null
$connectionData = $symbioticDatabase->findNamespaceConnectionName();
```

Multiple individual managers can work collaboratively and cross-functionally
----------------------------------------------------------------------------

[](#multiple-individual-managers-can-work-collaboratively-and-cross-functionally)

```
/**
* @var \Symbiotic\Database\Eloquent\EloquentManager $manager
 */
$capsuleOne = new \Symbiotic\Database\Eloquent\EloquentManager($config,\Illuminate\Database\Eloquent\Model::class);
$capsuleTwo = new \Symbiotic\Database\Eloquent\EloquentManager($config,\Symbiotic\Database\Eloquent\SymbioticModel::class);
$capsuleThree = new \Symbiotic\Database\Eloquent\EloquentManager($config,\Illuminate\Database\Eloquent\Model::class);

$capsuleOne->bootEloquent();
// we work with the first manager
$capsuleOne->popEloquent();

$capsuleThree->bootEloquent();
    // activate two managers at once
    $capsuleOne->bootEloquent();
        $capsuleTwo->bootEloquent();
        // working with a second manager
        $capsuleTwo->popEloquent();
    // we work with the first manager
    $capsuleOne->popEloquent();
// working with a third manager
$capsuleOne->popEloquent();
// terminated managers, if Laravel is initiated its connection manager will be installed back
```

Getting SchemaBuilder for migrations:

```
/**
* @var \Symbiotic\Database\Eloquent\EloquentManager $manager
 */
 $schema = $manager->getSchemaBuilder();

 $schema->create('table_name', static function(\Illuminate\Database\Schema\Blueprint $table) {
        $blueprint->string('name', 255);
 });
  $schema->drop('table_name');
```

Complete documentation on using models and setting up connections

Laravel .

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Total

2

Last Release

1125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a7ef7750fdc43614c00e641939b148f999b2771b930cf3cf1b18c66fe614de9c?d=identicon)[symbiotic](/maintainers/symbiotic)

### Embed Badge

![Health badge](/badges/symbiotic-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/symbiotic-eloquent/health.svg)](https://phpackages.com/packages/symbiotic-eloquent)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
