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

Commit 4e802cc

Browse files
committed
Merge branch 'develop'
2 parents 36ba63a + 1a7c0ce commit 4e802cc

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "package",
88
"minimum-stability": "dev",
99
"require": {
10-
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0"
10+
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|6.*"
1111
},
1212
"extra": {
1313
"laravel": {

src/TwoFactorAuth.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77

88
class TwoFactorAuth extends Model
99
{
10+
/**
11+
* The reference to the user model.
12+
*
13+
* @var string
14+
*/
15+
private $model;
16+
1017
/**
1118
* The attributes that are mass assignable.
1219
*
1320
* @var array
1421
*/
1522
protected $fillable = [
16-
'id', 'user_id'
23+
'id', 'user_id',
1724
];
1825

1926
/**
@@ -22,7 +29,7 @@ class TwoFactorAuth extends Model
2229
* @var array
2330
*/
2431
protected $hidden = [
25-
'id'
32+
'id',
2633
];
2734

2835
/**
@@ -39,10 +46,22 @@ class TwoFactorAuth extends Model
3946
*/
4047
public function user() : BelongsTo
4148
{
42-
return $this->belongsTo(
43-
\App\User::class,
44-
'user_id',
45-
config('twofactor-auth.models.user.primaryKey', 'id')
46-
);
49+
$model = $this->model();
50+
51+
return $this->belongsTo($model, 'user_id', (new $model)->getKeyName());
52+
}
53+
54+
/**
55+
* Get the reference to the user model.
56+
*
57+
* @return string
58+
*/
59+
private function model() : string
60+
{
61+
if (is_null($this->model)) {
62+
$this->model = config('twofactor-auth.model');
63+
}
64+
65+
return $this->model;
4766
}
4867
}

src/config/twofactor-auth.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,14 @@
8484

8585
/*
8686
|--------------------------------------------------------------------------
87-
| Model Setttings
87+
| Model
8888
|--------------------------------------------------------------------------
8989
|
90-
| Here you can specify some custom properties of the default user model.
90+
| Here you can optionally specify the user model that should be used. The
91+
| standard "Eloquent" user model is configured by default.
9192
|
9293
*/
9394

94-
'models' => [
95-
96-
'user' => [
97-
'primaryKey' => 'id',
98-
],
99-
100-
],
95+
'model' => \App\User::class,
10196

10297
];

0 commit comments

Comments
 (0)