I found a solution using the Carbon class (also make sure that the time on the server is correct, mine was still a different timezone)
on the Laravel PHP side I read the last_activity as
`public function sessions(Request $request) { $jsonReposeData = [];
foreach ($request->user()->getSessions()->get() as $currentSessionObject) {
// If the session age has not reached the SESSION_LIFETIME value
if ($currentSessionObject->LastActivity() > Carbon::now()->subMinutes(env('SESSION_LIFETIME'))->getTimestamp()) {
$currentSession = [
"row_id" => $currentSessionObject->RowID(),
"user" => $request->user()->getUser()->get()->first()->getFullName(),
"user_agent" => $currentSessionObject->UserAgent(),
"ip_address" => $currentSessionObject->IPAddress(),
"last_activity" => Carbon::parse($currentSessionObject->LastActivity())
//"last_activity" => $currentSessionObject->LastActivity()
//
];
array_push($jsonReposeData, $currentSession);
}
}
return response()
->json([
'success' => true,
'sessions' => $jsonReposeData,
'responseMessage' => 'Your sessions has been retreived'
]);
}`
On the javascript front end side, the data is read by (new Date)
<template> <v-simple-table :loading="loading"> <template v-slot:default> <thead> <tr> <th class="text-left"> User </th> <th class="text-left"> IP Address </th> <th class="text-left"> User Agent </th> <th class="text-left"> Last Activity </th> </tr> </thead> <tbody> <tr v-for="item in sessions" :key="item.row_id"> <td>{{ item.user }}</td> <td>{{ item.ip_address }}</td> <td>{{ item.user_agent }}</td> <td> {{ new Date(item.last_activity) }} </td> </tr> </tbody> </template> </v-simple-table> </template>
sheenilim08 liked this reply
I also posted the same question on http://www.php-forum.com/phpforum/viewtopic.php?f=2&t=29776&p=4422198#p4422198
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community