{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/8864","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/8864/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/8864/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/8864/events","html_url":"https://github.com/laravel/framework/issues/8864","id":80300198,"number":8864,"title":"DB::reconnect isnt working but DB:purge is","user":{"login":"leemason","id":1238646,"avatar_url":"https://avatars.githubusercontent.com/u/1238646?v=3","gravatar_id":"","url":"https://api.github.com/users/leemason","html_url":"https://github.com/leemason","followers_url":"https://api.github.com/users/leemason/followers","following_url":"https://api.github.com/users/leemason/following{/other_user}","gists_url":"https://api.github.com/users/leemason/gists{/gist_id}","starred_url":"https://api.github.com/users/leemason/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leemason/subscriptions","organizations_url":"https://api.github.com/users/leemason/orgs","repos_url":"https://api.github.com/users/leemason/repos","events_url":"https://api.github.com/users/leemason/events{/privacy}","received_events_url":"https://api.github.com/users/leemason/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2015-05-24T23:07:23Z","updated_at":"2016-08-26T05:29:10Z","closed_at":"2015-08-26T12:18:48Z","body":"not sure whats going here as the db area of laravel is like black magic to me, but im working on a multi tenancy app and use two main connections: tenants and tenant\r\n\r\nwhen i create a new tenant i need to set the tenant db config as needed (prefix etc) and reconnect to the db before running migrations (all done without artisan calling the migrator via the oic container).\r\n\r\nproblem i have just found is that setting the config and then calling DB::reconnect('tenant') doesnt seem to work?\r\n\r\nbut setting the config and then calling DB::purge('tenant'); DOES work.\r\n\r\nive had a look and i see no reason other than something caching somewhere the connection as i assume both methods should achieve the same end result."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/242633949","html_url":"https://github.com/laravel/framework/issues/8864#issuecomment-242633949","issue_url":"https://api.github.com/repos/laravel/framework/issues/8864","id":242633949,"user":{"login":"jcalonso","id":664474,"avatar_url":"https://avatars.githubusercontent.com/u/664474?v=3","gravatar_id":"","url":"https://api.github.com/users/jcalonso","html_url":"https://github.com/jcalonso","followers_url":"https://api.github.com/users/jcalonso/followers","following_url":"https://api.github.com/users/jcalonso/following{/other_user}","gists_url":"https://api.github.com/users/jcalonso/gists{/gist_id}","starred_url":"https://api.github.com/users/jcalonso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcalonso/subscriptions","organizations_url":"https://api.github.com/users/jcalonso/orgs","repos_url":"https://api.github.com/users/jcalonso/repos","events_url":"https://api.github.com/users/jcalonso/events{/privacy}","received_events_url":"https://api.github.com/users/jcalonso/received_events","type":"User","site_admin":false},"created_at":"2016-08-26T05:29:10Z","updated_at":"2016-08-26T05:29:10Z","body":"Im facing the same issue in Laravel 5.1 and 5.3 (havent try 5.2). This is the code that replicate this behaviour:\r\n\r\n```php\r\n<?php\r\n\r\nuse \\Illuminate\\Support\\Facades\\Config;\r\nuse \\Illuminate\\Support\\Facades\\DB;\r\n\r\nclass DbReconnectTest extends TestCase\r\n{\r\n    public function testDbReconnect()\r\n    {\r\n        Config::set('database.connections.mysql.database', 'tenant1');\r\n        DB::reconnect('mysql');\r\n        $connections = DB::getConnections();\r\n        $this->assertEquals('tenant1', $connections['mysql']->getDatabaseName(), 'Initial reconnect works since it the default');\r\n\r\n        Config::set('database.connections.mysql.database', 'tenant2');\r\n        DB::reconnect('mysql');\r\n        $connections = DB::getConnections();\r\n        $this->assertEquals('tenant2', $connections['mysql']->getDatabaseName(), 'The actual reconnect to another db fails');\r\n\r\n        DB::purge('mysql');\r\n        DB::reconnect('mysql');\r\n        $connections = DB::getConnections();\r\n        $this->assertEquals('tenant2', $connections['mysql']->getDatabaseName(), 'If purged, it works');\r\n    }\r\n}\r\n\r\n\r\n```\r\nOutput:\r\n```\r\n./vendor/bin/phpunit \r\nPHPUnit 5.5.3 by Sebastian Bergmann and contributors.\r\n\r\nF                                                                   1 / 1 (100%)\r\n\r\nTime: 78 ms, Memory: 10.50MB\r\n\r\nThere was 1 failure:\r\n\r\n1) DbReconnectTest::testDbReconnect\r\nThe actual reconnect to another db fails\r\nFailed asserting that two strings are equal.\r\n\r\n--- Expected\r\n+++ Actual\r\n@@ @@\r\n-'tenant2'\r\n+'tenant1'\r\n\r\n/Users/user/Desktop/laravelapp/tests/DbReconnectTest.php:18\r\n\r\nFAILURES!\r\nTests: 1, Assertions: 2, Failures: 1.\r\n\r\n```"}}
{"actor":{"display_login":"jcalonso"}}