Skip to content

Commit 3eb4dcb

Browse files
committed
Update LaravelUserMonitoringEventServiceProvider.php
1 parent 0aef2a6 commit 3eb4dcb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Providers/LaravelUserMonitoringEventServiceProvider.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Binafy\LaravelUserMonitoring\Providers;
44

55
use Binafy\LaravelUserMonitoring\Utills\Detector;
6+
use Binafy\LaravelUserMonitoring\Utills\UserUtils;
67
use Illuminate\Auth\Events\Login;
78
use Illuminate\Auth\Events\Logout;
89
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
@@ -14,25 +15,24 @@ class LaravelUserMonitoringEventServiceProvider extends EventServiceProvider
1415
public function boot(): void
1516
{
1617
$detector = new Detector();
17-
$guard = config('user-monitoring.user.guard');
1818
$table = config('user-monitoring.authentication_monitoring.table');
1919

2020
// Login Event
2121
if (config('user-monitoring.authentication_monitoring.on_login', false)) {
22-
Event::listen(function (Login $event) use ($detector, $guard, $table) {
22+
Event::listen(function (Login $event) use ($detector, $table) {
2323
DB::table($table)
2424
->insert(
25-
$this->insertData($guard, $detector, 'login'),
25+
$this->insertData($detector, 'login'),
2626
);
2727
});
2828
}
2929

3030
// Logout Event
3131
if (config('user-monitoring.authentication_monitoring.on_logout', false)) {
32-
Event::listen(function (Logout $event) use ($detector, $guard, $table) {
32+
Event::listen(function (Logout $event) use ($detector, $table) {
3333
DB::table($table)
3434
->insert(
35-
$this->insertData($guard, $detector, 'logout'),
35+
$this->insertData($detector, 'logout'),
3636
);
3737
});
3838
}
@@ -41,15 +41,16 @@ public function boot(): void
4141
/**
4242
* Get insert data.
4343
*/
44-
private function insertData(string $guard, Detector $detector, string $actionType): array
44+
private function insertData(Detector $detector, string $actionType): array
4545
{
4646
return [
47-
'user_id' => auth($guard)->id(),
47+
'user_id' => UserUtils::getUserId(),
4848
'action_type' => $actionType,
4949
'browser_name' => $detector->getBrowser(),
5050
'platform' => $detector->getDevice(),
5151
'device' => $detector->getDevice(),
5252
'ip' => request()->ip(),
53+
'user_guard' => UserUtils::getCurrentGuardName(),
5354
'page' => request()->url(),
5455
'created_at' => now(),
5556
'updated_at' => now(),

0 commit comments

Comments
 (0)