Skip to content

Commit ec0752f

Browse files
committed
Add previousLogin method
1 parent 6fb996f commit ec0752f

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/Entities/User.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ public function getPasswordHash(): ?string
242242
return $this->password_hash;
243243
}
244244

245+
/**
246+
* Returns the previous login information for this user
247+
*/
248+
public function previousLogin(): ?Login
249+
{
250+
/** @var LoginModel $logins */
251+
$logins = model(LoginModel::class);
252+
253+
return $logins->previousLogin($this);
254+
}
255+
245256
/**
246257
* Returns the last login information for this user as
247258
*/

src/Models/LoginModel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ public function recordLoginAttempt(
6767
$this->checkQueryReturn($return);
6868
}
6969

70+
/**
71+
* Returns the previous login information for the user,
72+
* useful to display to the user the last time the account
73+
* was accessed.
74+
*/
75+
public function previousLogin(User $user): ?Login
76+
{
77+
return $this->where('success', 1)
78+
->where('user_id', $user->id)
79+
->orderBy('id', 'desc')->get()
80+
->getRow(1, Login::class);
81+
}
82+
7083
/**
7184
* Returns the last login information for the user
7285
*/

0 commit comments

Comments
 (0)