From 280ae2bfdb6e47aeeba2b0b6e0e925feb9b95e33 Mon Sep 17 00:00:00 2001 From: Alessandro Benoit Date: Thu, 10 Oct 2019 13:59:16 +0200 Subject: [PATCH] Fix #615 - Use default config instead of env as connection --- README.md | 7 +++++++ config/activitylog.php | 5 +++-- tests/CustomDatabaseConnectionActivityModelTest.php | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9568ed73..24134d93 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,13 @@ return [ * used by the Activity model shipped with this package. */ 'table_name' => 'activity_log', + + /* + * This is the database connection that will be used by the migration and + * the Activity model shipped with this package. In case it's not set + * Laravel database.default will be used instead. + */ + 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), ]; ``` diff --git a/config/activitylog.php b/config/activitylog.php index 13b78452..a6558ecb 100644 --- a/config/activitylog.php +++ b/config/activitylog.php @@ -45,7 +45,8 @@ /* * This is the database connection that will be used by the migration and - * the Activity model shipped with this package. + * the Activity model shipped with this package. In case it's not set + * Laravel database.default will be used instead. */ - 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION', env('DB_CONNECTION', 'mysql')), + 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), ]; diff --git a/tests/CustomDatabaseConnectionActivityModelTest.php b/tests/CustomDatabaseConnectionActivityModelTest.php index dca0b363..0b571ee7 100644 --- a/tests/CustomDatabaseConnectionActivityModelTest.php +++ b/tests/CustomDatabaseConnectionActivityModelTest.php @@ -26,6 +26,16 @@ public function it_uses_a_custom_database_connection() $this->assertEquals($model->getConnectionName(), 'custom_sqlite'); } + /** @test */ + public function it_uses_the_default_database_connection_when_the_one_from_configuration_is_null() + { + config()->set('activitylog.database_connection', null); + + $model = new Activity(); + + $this->assertInstanceOf('Illuminate\Database\SQLiteConnection', $model->getConnection()); + } + /** @test */ public function it_uses_the_database_connection_from_model() {