Laravel-activitylog: Logging model events database connection issue

Created on 30 Apr 2020  路  2Comments  路  Source: spatie/laravel-activitylog

There is no option to set default connection in Logging model event while i am using multi-database
in setting it model __construct.
Kindly tell me how to define default connection from model or from session
image

question

Most helpful comment

Hey,
the package comes with a config value for the activity database connection.
https://github.com/spatie/laravel-activitylog/blob/469e78d6dd38baa7ef3a602f238f979afe2a4000/config/activitylog.php#L51

It's set in the activity model during construct. So you can update the config value on runtime, for example via middleware, and all activities created/retrieved from this point will use the configured connection.
https://github.com/spatie/laravel-activitylog/blob/469e78d6dd38baa7ef3a602f238f979afe2a4000/src/Models/Activity.php#L22-L24

All 2 comments

Hey,
the package comes with a config value for the activity database connection.
https://github.com/spatie/laravel-activitylog/blob/469e78d6dd38baa7ef3a602f238f979afe2a4000/config/activitylog.php#L51

It's set in the activity model during construct. So you can update the config value on runtime, for example via middleware, and all activities created/retrieved from this point will use the configured connection.
https://github.com/spatie/laravel-activitylog/blob/469e78d6dd38baa7ef3a602f238f979afe2a4000/src/Models/Activity.php#L22-L24

Yes its working in middlware. Thanks
config(['activitylog.database_connection' => 'mysql2']);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hesesses picture Hesesses  路  5Comments

ianrussel picture ianrussel  路  5Comments

lucianobosco picture lucianobosco  路  5Comments

DjKhireddine picture DjKhireddine  路  5Comments

marky291 picture marky291  路  4Comments