Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noweh/eloquent-dual-database
Custom Eloquent Builder for dual database (one for READ, and another for WRITE).
https://github.com/noweh/eloquent-dual-database
eloquent laravel
Last synced: 18 days ago
JSON representation
Custom Eloquent Builder for dual database (one for READ, and another for WRITE).
- Host: GitHub
- URL: https://github.com/noweh/eloquent-dual-database
- Owner: noweh
- License: mit
- Created: 2021-12-02T15:04:27.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-02T15:22:09.000Z (about 3 years ago)
- Last Synced: 2025-01-06T23:20:02.566Z (about 1 month ago)
- Topics: eloquent, laravel
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# DualDB plugin for Eloquent models
[](https://laravel.com/)
[](licence.md)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);
}
...
}
```