Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 5c16267

Browse files
committed
Added option to use a non-default primary key name for the user model.
1 parent 12512dd commit 5c16267

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/TwoFactorAuth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ class TwoFactorAuth extends Model
3939
*/
4040
public function user() : BelongsTo
4141
{
42-
return $this->belongsTo(\App\User::class);
42+
return $this->belongsTo(\App\User::class, config('twofactor-auth.models.user.pk', 'id'));
4343
}
4444
}

src/TwoFactorAuthenticable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait TwoFactorAuthenticable
1414
*/
1515
public function twoFactorAuth() : HasOne
1616
{
17-
return $this->hasOne(TwoFactorAuth::class);
17+
return $this->hasOne(TwoFactorAuth::class, $this->getKeyName());
1818
}
1919

2020
/**

src/config/twofactor-auth.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,18 @@
6464
'post' => '/auth/token',
6565
],
6666

67+
/*
68+
|--------------------------------------------------------------------------
69+
| Model setttings
70+
|--------------------------------------------------------------------------
71+
|
72+
| \App\User is used, but its primary key can be specified
73+
|
74+
*/
75+
'models' => [
76+
'user' => [
77+
'pk' => 'id'
78+
]
79+
],
80+
6781
];

0 commit comments

Comments
 (0)