2

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!

0

1 Answer 1

2

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(); 
Sign up to request clarification or add additional context in comments.

4 Comments

I will try that. That looks promising :)
I am getting this error: Non-static method Illuminate\Database\Eloquent\Model::setConnection() should not be called statically
Updated my answer
perfect! This is what i'm looking for :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.