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

UserTableSeeder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 47
ccs 0
cts 19
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 4 1
B seedAdminUser() 0 25 2
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