I'm using Sentinel for authorization on my Laravel project. Now i'm trying to add Laravel-activitylog from Spatie. Activity log uses default auth driver for logging user activity. How can i change driver to use the one from Sentinel. I'm new at Laravel and have trouble implementing this. Any help would be greatly appreciated. Kind regards.
Asked
Active
Viewed 1,486 times
2 Answers
0
It's right in the config file.
'default_auth_driver' => null,
Just set it to whatever you're using.
https://docs.spatie.be/laravel-activitylog/v2/installation-and-setup
-
I saw that option in config, but I don't know what to put there, tried 'sentinel' but i get ERROR: Auth guard [Sentinel] is not defined. – Primož Jan 30 '18 at 10:57
-
Sentinel likely uses either `session` or `api` as it's guards. I would assume it builds on top of the laravel implementations. – Jan 30 '18 at 11:00
-
Auth guards that are defined in auth.php are web and api, those two work the same as null option (in activitylog.php). Logging works, but I don't get the causer model. The only thing that worked was changing ActivityLogger.php by replacing $this->causedBy = $auth->guard($this->authDriver)->user(); to $this->causedBy = Sentinel::getUser(); but this is not a proper solution. As i said in opening post, I'm new to laravel and have hard time figuring this out. – Primož Jan 31 '18 at 07:12
-
I just looked at the repository. You don't need to change the source code. You pass either a user model instance or id to `->causedBy()`. It normalizes this under the hood for you. https://github.com/spatie/laravel-activitylog/blob/65927f3f3ac1d2215c30ddb681791162c7d40689/src/ActivityLogger.php#L162. – Jan 31 '18 at 07:29
-
It also states "If you're not using causedBy the package will automatically use the logged in user." https://docs.spatie.be/laravel-activitylog/v2/basic-usage/logging-activity#setting-a-causer – Jan 31 '18 at 07:30
-
'If you're not using causedBy the package will automatically use the logged in user.' this part does not work with sentinel, I don't get the logged user. Look like i'll have to manually log, instead of using LogsActivity trait. – Primož Jan 31 '18 at 08:10
0
I changed variable at __construct function in ActivityLogger.php
$this->causedBy = \Sentinel::check();

fiazn
- 1
-
ActivityLogger.php can be find here path_to_project\vendor\spatie\laravel-activitylog\src\ActivityLogger.php edit value of $this->causedBy inside function __construct – fiazn Aug 28 '18 at 09:14