Skip to content

Commit

Permalink
Fix spatie#615 - Use default config instead of env as connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Benoit committed Oct 10, 2019
1 parent 808a3e5 commit 1f0dfcf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
composer.lock
vendor
.phpunit.result.cache
.idea
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
```

Expand Down
5 changes: 3 additions & 2 deletions config/activitylog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
10 changes: 10 additions & 0 deletions tests/CustomDatabaseConnectionActivityModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 1f0dfcf

Please sign in to comment.