Skip to content
Discussion options

You must be logged in to vote

But isn't that redundant? I mean, get() could automatically choose read and update() could automatically choose write:

User::withSeparateReadWriteConnection()->where('active', 1)->get();      // uses read connection
User::withSeparateReadWriteConnection()->whereKey($id)->update([...]);  // uses write connection

or

User::withSeparateReadWriteConnection(fn (Builder $query) => $query->where('active', 1)->get());      // uses read connection
User::withSeparateReadWriteConnection(fn (Builder $query) => $query->whereKey($id)->update([...]));  // uses write connection

or

class User extends Model
{
    protected bool $withSeparateReadWriteConnection = true;
}
User::query()->where('active', 1)->get(…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@shaedrich
Comment options

@ShaungBhone
Comment options

@shaedrich
Comment options

Answer selected by ShaungBhone
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants