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

Save Causer when using LogsActivity trait #503

Closed
jariesdev opened this issue Mar 23, 2019 · 5 comments · Fixed by #866 or #787
Closed

Save Causer when using LogsActivity trait #503

jariesdev opened this issue Mar 23, 2019 · 5 comments · Fixed by #866 or #787

Comments

@jariesdev
Copy link

Im using the trait LogsActivity on my model and its saves the event happened but the causer is not saved. I have 2 users Model which is the Admin and Users Model. Did I miss something?

@Gummibeer
Copy link
Collaborator

The causer is saved if the current guard knows about an user instance.
If you don't have an authenticated user in your guard this won't work.

If you want to customize the causer check the tapActivity() method.

@jariesdev
Copy link
Author

Sorry but do I tell the causer to use my guard('admin') ? I know that tapActivity() is used if I'm going to use activity() helper function.

@Gummibeer
Copy link
Collaborator

$this->authDriver = $config['activitylog']['default_auth_driver'] ?? $auth->getDefaultDriver();

With this config key you can set your default auth driver. Atm there is no way to change the used auth driver on runtime. But the ActivityLogger class is macroable and is bind as a service - so you can extend it.

The tapActivity() method is used for auto logged activities. For custom ones it's tap().

@jny986
Copy link

jny986 commented Oct 10, 2019

@jariesdev I would try something like the following to implement it into your system

On the model that you are logging activity add something like this

public function tapActivity(Activity $activity, string $eventName)
{
    if (Auth::check()) {
        $activity->causedBy = Auth::user();
    }
}

This if you auth is setup correctly should provide the causedBy to the activity logger.

I have created a pull request for this issue as well

@Gummibeer Gummibeer self-assigned this Mar 13, 2020
@github-actions github-actions bot added the stale label May 4, 2020
@Gummibeer Gummibeer removed the stale label May 4, 2020
@spatie spatie deleted a comment from github-actions bot May 4, 2020
@Gummibeer Gummibeer mentioned this issue Sep 16, 2020
Merged
9 tasks
@nagi1 nagi1 mentioned this issue Apr 9, 2021
10 tasks
This was linked to pull requests Apr 19, 2021
Merged
nagi1 referenced this issue in nagi1/laravel-activitylog Apr 24, 2021
@Gummibeer
Copy link
Collaborator

I will close this issue even if v4 isn't released yet. But the task itself is done and I want to check which tasks are really open. Please keep an eye on #787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants