Skip to content

Commit

Permalink
Add usingConnection method to DatabaseManager
Browse files Browse the repository at this point in the history
antonkomarev committed May 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent dce4429 commit 9b65240
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Database/DatabaseManager.php
Original file line number Diff line number Diff line change
@@ -245,6 +245,22 @@ public function reconnect($name = null)
return $this->refreshPdoConnections($name);
}

/**
* Set the database connection for the callback execution.
*
* @param string $name
* @param callable $callback
* @return void
*/
public function usingConnection(string $name, callable $callback)
{
$previousName = $this->getDefaultConnection();

$this->setDefaultConnection($name);
$callback();
$this->setDefaultConnection($previousName);
}

/**
* Refresh the PDO connections on a given connection.
*

0 comments on commit 9b65240

Please sign in to comment.