Level 9
solved. make middleware and store data from within it instead of event listener.
Summer Sale! All accounts are 50% off this week.
I'm using file sessions driver in my app and I want to store data in my sessions table not for maintaining user session but just to track user login activity. where should I but my piece of code? I put it in listener for login event and the data inserted successfully but the session id stored in database table doesn't equal session id of the file.
Here's my handle function in my listener class
public function handle($event)
{
try {
$data = [
'id' => session()->getId(),
'user_id' => request()->user()->id,
'ip_address' => request()->ip(),
'user_agent' => request()->userAgent(),
'last_activity' => Carbon::now()->getTimestamp()
];
Session::updateOrCreate($data, $data);
} catch (\Exception $exception) {
}
}
solved. make middleware and store data from within it instead of event listener.
Please or to participate in this conversation.