Completed
Pull Request — master (#10)
by alexfloppy
07:51
created

UsersRolesTableSeeder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 14 2
1
<?php
2
3
namespace App\Seeds;
4
5
use App\Models\Role;
6
use App\Models\User;
7
use Illuminate\Database\Seeder;
8
9
/**
10
 * This is the comments table seeder class.
11
 *
12
 * @author Graham Campbell <[email protected]>
13
 */
14
class UsersRolesTableSeeder extends Seeder
15
{
16
    /**
17
     * Run the database seeding.
18
     *
19
     * @return void
20
     */
21
    public function run()
22
    {
23
        $admin = User::find(1);
24
        $users = User::where('name', '!=', 'Admin')->get();
25
26
        $roleAdmin = Role::where('name', 'admin')->first();
27
        $roleUser = Role::where('name', 'user')->first();
28
29
        $admin->attachRole($roleAdmin);
30
31
        foreach ($users as $user) {
32
            $user->attachRole($roleUser);
33
        }
34
    }
35
}
36