noweh / eloquent-dual-database
Custom Eloquent Builder for dual database.
1.0.1
2021-12-02 15:14 UTC
Requires
- php: >=7.4
- illuminate/database: ^6.0|^7.0|^8.0
This package is auto-updated.
Last update: 2024-11-20 00:51:44 UTC
README
This package provides a trait that override the Eloquent Builder in order to improve the management of Dual DB, with one DB for Read and Another for Write.
Indeed, this plugin allows you to retrieve freshly inserted data, even if the have not yet been duplicated on the Read Database.
Installation
First you need to add the component to your composer.json
composer require noweh/laravel-plugin-dual-database
Update your packages with composer update or install with composer install.
Simple Usage
Use the trait Noweh\EloquentDualDatabase\EloquentDualDatabaseTrait
in your Model.
Example
use Noweh\EloquentDualDatabase\EloquentDualDatabaseTrait;
class MyModel extends Model
{
use EloquentDualDatabaseTrait;
...
}
Or, for a custom usage
Override the Eloquent Method newEloquentBuilder($query)
in your Model.
Example
use Noweh\EloquentDualDatabase\CustomEloquentBuilder;
class MyModel extends Model
{
public function newEloquentBuilder($query): Builder
{
...
return new CustomEloquentBuilder($query);
}
...
}