Skip to content

Commit 868d8fc

Browse files
committed
Get the user model instance from admin config, fixes Laravel 8 User model errors
1 parent 0dff75a commit 868d8fc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/UserCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace NickDeKruijk\Admin;
44

5-
use App\User;
65
use Illuminate\Console\Command;
76
use Illuminate\Support\Str;
87

@@ -33,14 +32,25 @@ public function __construct()
3332
parent::__construct();
3433
}
3534

35+
/**
36+
* Get the user model instance from admin config
37+
*
38+
* @return User;
39+
*/
40+
public static function userModel()
41+
{
42+
$model = config('admin.modules.users.model');
43+
return new $model;
44+
}
45+
3646
/**
3747
* Execute the console command.
3848
*
3949
* @return mixed
4050
*/
4151
public function handle()
4252
{
43-
$user = User::where('email', $this->arguments()['email'])->first();
53+
$user = self::userModel()->where('email', $this->arguments()['email'])->first();
4454
$password = Str::random(40);
4555
echo 'User ' . $this->arguments()['email'] . ' ';
4656
if ($user) {
@@ -51,7 +61,7 @@ public function handle()
5161
}
5262
} else {
5363
echo 'created with ';
54-
$user = new User;
64+
$user = self::userModel();
5565
$user->email = $this->arguments()['email'];
5666
$user->name = $this->arguments()['email'];
5767
$user[config('admin.role_column')] = $this->arguments()['role'] ?: 'admin';

0 commit comments

Comments
 (0)