PinoyStackOverflower
PinoyStackOverflower

Reputation: 5302

Laravel Eloquent multiple database

I have multiple database connected into my web app.

These are: write and read

I have this eloquent database query:

$users = User::whereIsAdmin(0)->get();

I want this db query to use the read database since by default my app is reading in the write database.

How would I do that?

Thanks!

Upvotes: 2

Views: 1004

Answers (1)

Taha Paksu
Taha Paksu

Reputation: 15616

I looked at the source code of Laravel Eloquent Models, and here:

https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Model.php#L303

It says on should be used to change connections.

So:

User::on("read")->whereIsAdmin(0)->get();

Upvotes: 2

Related Questions