CodeIgniter Forums
lastlogin shield - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: lastlogin shield (/showthread.php?tid=87820)



lastlogin shield - destor77 - 06-04-2023

I'm trying to get the latest shield login.
I do the following:
PHP Code:
$tmpUser auth()->getProvider();

$user $tmpUser->findById($users[$i]->id);

$lastLogin $user->lastLogin();
$tmp $lastLogin->toArray();
echo
'<pre>';print_r($tmp['date']->format('Y-m-d H:i'));echo'</pre>';
d($tmp['date']->format('Y-m-d H:i'));exit(); 


This returns me:
[Image: sc1.png]

But when I want to save it to an array:
PHP Code:
$tmpUser auth()->getProvider();

$user $tmpUser->findById($users[$i]->id);

$lastLogin $user->lastLogin();
$tmp $lastLogin->toArray();
            
$userList
[] = [
    'id' => $users[$i]->id,
    'user' => $users[$i]->username,
    'grupos' => $grupo,
    'lastLogin' => $tmp['date']->format('Y-m-d H:i'), 


it returns me this error:
[Image: sc2.png]

and I don't understand why with d or print_r/var_dump it prints the value, but I can't assign it to the array


RE: lastlogin shield - datamweb - 09-03-2023

Hi @destor77, try the following method:

PHP Code:
        
        $lastLogin 
$user->lastLogin()->date;
        
        $userList
[] = [
            // other ...
            'lastLogin' => $lastLogin->format('Y-m-d H:i')
        ];

        dd($userList);