forked from rappasoft/laravel-authentication-log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticationLoggable.php
53 lines (42 loc) · 1.29 KB
/
AuthenticationLoggable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Rappasoft\LaravelAuthenticationLog\Traits;
use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;
trait AuthenticationLoggable
{
public function authentications()
{
return $this->morphMany(AuthenticationLog::class, 'authenticatable')->latest('login_at');
}
public function latestAuthentication()
{
return $this->morphOne(AuthenticationLog::class, 'authenticatable')->latestOfMany('login_at');
}
public function notifyAuthenticationLogVia(): array
{
return ['mail'];
}
public function lastLoginAt()
{
return $this->authentications()->first()?->login_at;
}
public function lastSuccessfulLoginAt()
{
return $this->authentications()->whereLoginSuccessful(true)->first()?->login_at;
}
public function lastLoginIp()
{
return $this->authentications()->first()?->ip_address;
}
public function lastSuccessfulLoginIp()
{
return $this->authentications()->whereLoginSuccessful(true)->first()?->ip_address;
}
public function previousLoginAt()
{
return $this->authentications()->skip(1)->first()?->login_at;
}
public function previousLoginIp()
{
return $this->authentications()->skip(1)->first()?->ip_address;
}
}