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: 29 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 (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-02T15:22:09.000Z (almost 3 years ago)
- Last Synced: 2024-05-19T07:20:34.076Z (6 months 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
[![Laravel](https://img.shields.io/badge/Laravel-v6/8-828cb7.svg?logo=Laravel&color=FF2D20)](https://laravel.com/)
[![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](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);
}
...
}
```