Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to define table name in environment file #1334

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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