Completed
Push — master ( e43e24...a5d827 )
by ARCANEDEV
05:31
created

UserTableSeeder::seedAdminUser()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
ccs 0
cts 13
cp 0
rs 8.8571
cc 2
eloc 15
nc 2
nop 0
crap 6
1
<?php namespace Arcanesoft\Auth\Seeds\Foundation;
2
3
use Arcanedev\LaravelAuth\Services\UserConfirmator;
4
use Arcanesoft\Auth\Bases\Seeder;
5
use Arcanesoft\Auth\Models\Role;
6
use Arcanesoft\Auth\Models\User;
7
use Carbon\Carbon;
8
9
/**
10
 * Class     UserTableSeeder
11
 *
12
 * @package  Arcanesoft\Auth\Seeds\Foundation
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class UserTableSeeder extends Seeder
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Main Functions
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * Run the database seeds.
23
     */
24
    public function run()
25
    {
26
        $this->seedAdminUser();
27
    }
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Other Functions
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * Seed the admin account.
35
     */
36
    private function seedAdminUser()
37
    {
38
        /** @var Role $adminRole */
39
        $adminRole = Role::where('slug', 'administrator')->first();
40
41
        $adminUser = new User([
42
            'username'   => 'admin',
43
            'first_name' => 'Super',
44
            'last_name'  => 'ADMIN',
45
            'email'      => env('ADMIN_EMAIL',    '[email protected]'),
46
            'password'   => env('ADMIN_PASSWORD', 'password'),
47
        ]);
48
49
        $adminUser->is_admin  = true;
50
        $adminUser->is_active = true;
51
52
        if (UserConfirmator::isEnabled()) {
53
            $adminUser->is_confirmed = true;
54
            $adminUser->confirmed_at = Carbon::now();
55
        }
56
57
        $adminUser->save();
58
59
        $adminRole->attachUser($adminUser);
60
    }
61
}
62