Welcome Guest, Not a member yet? Register   Sign In
lastlogin shield
#1

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
Reply
#2

Hi @destor77, try the following method:

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

        dd($userList); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB