timetofly
timetofly

Reputation: 3077

Laravel: what happens if I have separate read/write connections configured, and do both reads and writes within a transaction?

If I have reads/writes configured in database.php, and I start a transaction like DB::transaction(function() { // series of reads and writes }), will everything run on the write connection, or will there be two separate transactions, or will it just explode?

Upvotes: 4

Views: 1397

Answers (2)

Steven M
Steven M

Reputation: 594

https://github.com/laravel/framework/pull/3272

getReadPdo() now checks if the query is within a transaction, and in that case returns the same PDO connection as the write.

Upvotes: 3

Kryten
Kryten

Reputation: 15780

If you're saying you want to do both reads and writes within a transaction using the same connection, then that will work fine - you can read from the database during the transaction.

If you're saying you want to read using one connection while you're writing as part of a transaction on the other connection, that will work fine too although you might have times when the read connection will block until the write connection transaction is finished.

Upvotes: 1

Related Questions