Skip to content

Commit

Permalink
Merge pull request #1334 from edwinvdpol/patch-1
Browse files Browse the repository at this point in the history
Possibility to define table name in environment file
  • Loading branch information
Nielsvanpach authored Oct 18, 2024
2 parents 7b33cae + edc6ed4 commit e0fc281
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/activitylog.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* This is the name of the table that will be created by the migration and
* used by the Activity model shipped with this package.
*/
'table_name' => 'activity_log',
'table_name' => env('ACTIVITY_LOGGER_TABLE_NAME', 'activity_log'),

/*
* This is the database connection that will be used by the migration and
Expand Down
13 changes: 10 additions & 3 deletions docs/installation-and-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ return [

/*
* You can specify an auth driver here that gets user models.
* If this is null we'll use the default Laravel auth driver.
* If this is null we'll use the current Laravel auth driver.
*/
'default_auth_driver' => null,

Expand All @@ -68,7 +68,7 @@ return [

/*
* This model will be used to log activity.
* It should be implements the Spatie\Activitylog\Contracts\Activity interface
* It should implement the Spatie\Activitylog\Contracts\Activity interface
* and extend Illuminate\Database\Eloquent\Model.
*/
'activity_model' => \Spatie\Activitylog\Models\Activity::class,
Expand All @@ -77,6 +77,13 @@ return [
* This is the name of the table that will be created by the migration and
* used by the Activity model shipped with this package.
*/
'table_name' => 'activity_log',
'table_name' => env('ACTIVITY_LOGGER_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's database.default will be used instead.
*/
'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'),
];
```
9 changes: 5 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function getPackageProviders($app)

public function getEnvironmentSetUp($app)
{
config()->set('activitylog.table_name', 'activity_log');
config()->set('activitylog.database_connection', 'sqlite');
config()->set('database.default', 'sqlite');
config()->set('database.connections.sqlite', [
Expand All @@ -45,15 +46,15 @@ public function getEnvironmentSetUp($app)
));
}

protected function setUpDatabase()
protected function setUpDatabase(): void
{
$this->migrateActivityLogTable();

$this->createTables('articles', 'users');
$this->seedModels(Article::class, User::class);
}

protected function migrateActivityLogTable()
protected function migrateActivityLogTable(): void
{
require_once __DIR__.'/../database/migrations/create_activity_log_table.php.stub';
require_once __DIR__.'/../database/migrations/add_event_column_to_activity_log_table.php.stub';
Expand All @@ -64,7 +65,7 @@ protected function migrateActivityLogTable()
(new AddBatchUuidColumnToActivityLogTable())->up();
}

protected function createTables(...$tableNames)
protected function createTables(...$tableNames): void
{
collect($tableNames)->each(function (string $tableName) {
Schema::create($tableName, function (Blueprint $table) use ($tableName) {
Expand All @@ -86,7 +87,7 @@ protected function createTables(...$tableNames)
});
}

protected function seedModels(...$modelClasses)
protected function seedModels(...$modelClasses): void
{
collect($modelClasses)->each(function (string $modelClass) {
foreach (range(1, 0) as $index) {
Expand Down

0 comments on commit e0fc281

Please sign in to comment.