Test Setup Failed
Pull Request — master (#34)
by Jeremy
04:44
created

DefaultUsersTableSeeder::run()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 4
nop 0
dl 0
loc 36
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace jeremykenedy\LaravelRoles\Database\Seeds;
4
5
use Illuminate\Database\Seeder;
6
7
class DefaultUsersTableSeeder extends Seeder
8
{
9
    /**
10
     * Run the database seeds.
11
     *
12
     * @return void
13
     */
14
    public function run()
15
    {
16
        $userRole = config('roles.models.role')::where('name', '=', 'User')->first();
17
        $adminRole = config('roles.models.role')::where('name', '=', 'Admin')->first();
18
        $permissions = config('roles.models.permission')::all();
19
20
        /*
21
         * Add Users
22
         *
23
         */
24
        echo "\e[32mSeeding:\e[0m DefaultUsersTableSeeder\r\n";
25
26
        if (config('roles.defaultUserModel')::where('email', '=', '[email protected]')->first() === null) {
27
            $newUser = config('roles.defaultUserModel')::create([
28
                'name'     => 'Admin',
29
                'email'    => '[email protected]',
30
                'password' => bcrypt('password'),
31
            ]);
32
33
            $newUser->attachRole($adminRole);
34
            foreach ($permissions as $permission) {
35
                $newUser->attachPermission($permission);
36
            }
37
            echo "\e[32mSeeding:\e[0m DefaultUsersTableSeeder - User:[email protected]\r\n";
38
        }
39
40
        if (config('roles.defaultUserModel')::where('email', '=', '[email protected]')->first() === null) {
41
            $newUser = config('roles.defaultUserModel')::create([
42
                'name'     => 'User',
43
                'email'    => '[email protected]',
44
                'password' => bcrypt('password'),
45
            ]);
46
47
            $newUser;
48
            $newUser->attachRole($userRole);
49
            echo "\e[32mSeeding:\e[0m DefaultUsersTableSeeder - User:[email protected]\r\n";
50
        }
51
    }
52
}
53