PHPackages                             envor/laravel-datastore - 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. envor/laravel-datastore

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

envor/laravel-datastore
=======================

On Prem Laravel

v3.0.0(1y ago)15.5k↑25%[3 PRs](https://github.com/envor/laravel-datastore/pulls)2MITPHPPHP ^8.1CI passing

Since Feb 15Pushed 1mo agoCompare

[ Source](https://github.com/envor/laravel-datastore)[ Packagist](https://packagist.org/packages/envor/laravel-datastore)[ Docs](https://github.com/envor/laravel-datastore)[ RSS](/packages/envor-laravel-datastore/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (31)Used By (2)

On Prem Laravel
===============

[](#on-prem-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a52c8a8c1e4a76fd54a0e23f03b4e4913abcc0febf107c3a348402fc03d56661/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e766f722f6c61726176656c2d6461746173746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-datastore)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3046a55aa9a275e6d8029804c534d1fe7c8301b00a4c14b5101da526827c9b7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d6461746173746f72652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-datastore/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e659dba048b3239937413938d5cf9dc21dec11b0696fe7cb91871c33820d94c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656e766f722f6c61726176656c2d6461746173746f72652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/envor/laravel-datastore/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1f363b40ea2d1864686bac650e0850eb1344ef69c629f4dc2a026c244144cea8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e766f722f6c61726176656c2d6461746173746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/envor/laravel-datastore)

A simple strategy for handling dynamic databases of varying types

Upgrade Guide
-------------

[](#upgrade-guide)

Upgrading from 1.x to 2.x.

2x does not push middleware by default, or configure context by default. To continue using as before add the following to your project's .env file:

```
DATASTORE_PUSH_CONTEXT_MIDDLEWARE=true
AUTOCONFIGURE_DEFAULT_CONTEXT=true
```

2x does not require `envor/platform` by default, Next you will need to manually require `envor/platform`

```
composer require envor/platform
```

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

[](#installation)

You can install the package via composer:

```
composer require envor/laravel-datastore
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="datastore-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="datastore-config"
```

This is the contents of the published config file:

```
return [
    'model' => \Envor\Datastore\Models\Datastore::class,
    'create_databases' => env('DATASTORE_CREATE_DATABASES', true),
    'push_middleware' => env('DATASTORE_PUSH_CONTEXT_MIDDLEWARE', false),
    'autoconfigure_default_context' => env('AUTOCONFIGURE_DEFAULT_CONTEXT', false),
];
```

Usage
-----

[](#usage)

You actually don't need to use the model or even run migrations. You can use the factory directly like so:

```
use Envor\Datastore\DatabaseFactory;

$sqlite = DatabaseFactory::newDatabase('mydb', 'sqlite');

// Envor\Datastore\Databases\SQLite {#2841 ...

$sqlite->create();

// true

$sqlite->name;

// ...storage/app/datastore/mydb.sqlite

$sqlite->connection;

// mydb

$sqlite->migrate();

  //  INFO  Preparing database.

  // Creating migration table ................ 9.55ms DONE

$sqlite->configure();

config('database.default');

// "mydb"

config('database.connections.mydb');

// [
//     "driver" => "sqlite",
//     "url" => null,
//     "database" => "...storage/app/datastore/mydb.sqlite",
//     "prefix" => "",
//     "foreign_key_constraints" => true,
//     "name" => "mydb",
// ]
```

```
    /**
     * Create a newly registered user.
     *
     * @param  array  $input
     */
    public function create(array $input): User
    {
        $create = function () use ($input) {
            Validator::make($input, [
                'name' => ['required', 'string', 'max:255'],
                'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
                'password' => $this->passwordRules(),
                'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
            ])->validate();

            return DB::transaction(function () use ($input) {
                return tap(User::create([
                    'name' => $input['name'],
                    'email' => $input['email'],
                    'password' => Hash::make($input['password']),
                ]), function (User $user) {
                    $this->createTeam($user);
                });
            });
        };

        SQLite::make(database_path('my_backup.sqlite'))
            ->create()
            ->migratePath('database/migrations/platform')
            ->migrate()
            ->run($create)
            ->disconnect();

        MariaDB::make('backup')
            ->create()
            ->migratePath('database/migrations/platform')
            ->migrate()
            ->run($create)
            ->disconnect();

        return MariaDB::make('datastore')
            ->create()
            ->migratePath('database/migrations/platform')
            ->migrate()
            ->run($create)
            ->return();
    }
```

Middleware
----------

[](#middleware)

You can use the 'datastore.context' middleware to get the app to behave in the context of the current datastore;

```
Route::get('/contexed', fn() => 'OK')->middleware('datastore.context');

// or
Route::get('/contexed', fn() => 'OK')->middleware(\Envor\Datastore\DatastoreContextMiddleware::class);

// will use the authenticated user to configure a database
```

Your user must implement the `HasDatastoreContext` interface in order for this to work.

```
...
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements \Envor\Datastore\Contracts\HasDatastoreContex
{
    use \Envor\Datastore\Concerns\BelongsToDatastore

    public function datastoreContext(): \Envor\Datastore\Contracts\ConfiguresDatastore;
    {
        return $this->datastore;
    }
}
```

Here are the relevant interfaces:

```
interface HasDatastoreContext
{
    public function datastoreContext(): ?\Envor\Datastore\Contracts\ConfiguresDatastore;
}

interface ConfiguresDatastore
{
    public function configure();

    public function use();

    public function database(): ?\Envor\Datastore\Datastore;
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [inmanturbo](https://github.com/envor)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance67

Regular maintenance activity

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

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 ~11 days

Recently: every ~34 days

Total

27

Last Release

511d ago

Major Versions

v1.x-dev → v2.0.02024-10-05

v2.x-dev → v3.0.02024-12-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/0261babef618b8fb3bfcea84376ed5e71e7169586eb8de63a6550c2e7ea653a6?d=identicon)[inmanturbo](/maintainers/inmanturbo)

---

Top Contributors

[![inmanturbo](https://avatars.githubusercontent.com/u/47095624?v=4)](https://github.com/inmanturbo "inmanturbo (153 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

laravellaravel datastoreenvor

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/envor-laravel-datastore/health.svg)

```
[![Health](https://phpackages.com/badges/envor-laravel-datastore/health.svg)](https://phpackages.com/packages/envor-laravel-datastore)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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