|
1
|
|
|
<?php namespace Arcanesoft\Auth\Seeds\Foundation; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LaravelAuth\Services\UserConfirmator; |
|
4
|
|
|
use Arcanedev\Support\Database\Seeder; |
|
5
|
|
|
use Arcanesoft\Auth\Models\Role; |
|
6
|
|
|
use Arcanesoft\Auth\Models\User; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class UserTableSeeder |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanesoft\Auth\Seeds\Foundation |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class UserTableSeeder extends Seeder |
|
15
|
|
|
{ |
|
16
|
|
|
/* ----------------------------------------------------------------- |
|
17
|
|
|
| Main Methods |
|
18
|
|
|
| ----------------------------------------------------------------- |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Run the database seeds. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function run() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->seedAdminUser(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/* ----------------------------------------------------------------- |
|
30
|
|
|
| Other Methods |
|
31
|
|
|
| ----------------------------------------------------------------- |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Seed the admin account. |
|
36
|
|
|
*/ |
|
37
|
|
|
private function seedAdminUser() |
|
38
|
|
|
{ |
|
39
|
|
|
tap(new User($this->getAdminUserAttributes()), function (User $admin) { |
|
40
|
|
|
$admin->save(); |
|
41
|
|
|
|
|
42
|
|
|
/** @var \Arcanesoft\Auth\Models\Role $adminRole */ |
|
43
|
|
|
$adminRole = Role::admin()->first(); |
|
44
|
|
|
$adminRole->attachUser($admin); |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the admin user's attributes. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
private function getAdminUserAttributes() |
|
54
|
|
|
{ |
|
55
|
|
|
$attributes = [ |
|
56
|
|
|
'username' => 'admin', |
|
57
|
|
|
'first_name' => 'Super', |
|
58
|
|
|
'last_name' => 'ADMIN', |
|
59
|
|
|
'email' => env('ADMIN_EMAIL', '[email protected]'), |
|
60
|
|
|
'password' => env('ADMIN_PASSWORD', 'password'), |
|
61
|
|
|
'is_admin' => true, |
|
62
|
|
|
'activated_at' => $now = now(), |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
if (UserConfirmator::isEnabled()) |
|
66
|
|
|
$attributes['confirmed_at'] = $now; |
|
67
|
|
|
|
|
68
|
|
|
return $attributes; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|