-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
[2.1.0] Document integrating spatie/laravel-activitylog #164
Comments
I was talking with @stancl about this earlier today. I haven't had a chance to test it yet, but we were considering keeping the default connection (in the activitylog config file) set to central or mysql or whatever your central connection is, and using the bootstrapping event to set that config key to |
I wonder if that default connection parameter could fallback to the Laravel default connection instead of the other way around. Pinging @Gummibeer for input. |
I have ended up finding a way to do it. I discovered that the Activity model sets the connectionName and the tableName in the Model class in the construct is it is not already set. I simply created the following class to work with the Activity Model
It is a little bit of a hack but if you can find a way to use the events to overwrite the connection for packages like this it would be worth doing. |
I'd suggest keeping the DB in the activity log config central and using this in AppServiceProvider: Tenancy::hook('bootstrapped', function ($tenantManager) {
config(['activitylog.connection', $tenantManager->getTenant()->getDatabaseConnection()]);
}); And on the Hope that makes sense, I'm writing this on mobile. @Gummibeer I was going to open an issue. I think activitylog should fallback to the default DB connection, because:
|
During config loading we fall back to the default Laravel env. But I think you mean something like |
Yeah, that's what I meant. The connection is set each time the model is constructed. Since models aren't singletons, I think it would solve it. I'll take a better look at this in the afternoon when I'm on my computer. |
You can also set the connection to null and it should work. No need for hooks. |
@stancl I tried your suggestion of using the booted hook however it did not work even after I corrected a slight issue with your code. Setting the Activity Log Connection to null does work however. Thanks for the suggestion. If I get a moment I will create a pull request for documentation of Spatie Activity Log |
@jny986 Glad to hear that. No need to make a PR, I will be writing a documentation page specifically about integrating Spatie packages. |
Hi @stancl , love this package. From what I read from the docs, it seems that we can only use 1 option rather than both? Say if I would like to log in the central, AND in the tenant scope, is that possible just by setting db_connection to null? Thank you |
Bumping the previous question, @stancl, thanks! |
I am trying to integrate the spatie/laravel-activitylog , however, it is not picking up and saving to the tenant.
Is there a way to get this working to save to the DB for system if not a tenant domain and to the tenant if for their domains.
Any help would be appreciated!
The text was updated successfully, but these errors were encountered: