Skip to content

Change logName before creating #958

Answered by Gummibeer
argo-uka asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, you could define a tapActivity() method on your model which can change the activity before it's persisted. But you need some fancy way to transfer the calling method to this tap method.
Without any container usage or similar global variable holder you could use debug_backtrace() for example.

Another option would be

$default = config('activitylog.default_log_name');
config('activitylog.default_log_name', 'my_new_log_name');
$model = MyModel::create(...);
config('activitylog.default_log_name', default');

return $model;

You could make this more readable and reusable by adding a macro to the ActivityLogger:

ActivityLogger::macro('withLogName', function(string $logName, Closure $callback)…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@argo-uka
Comment options

Answer selected by argo-uka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants