Completed
Push — master ( 2da897...c93f74 )
by Sherif
03:39
created

AssignRelationsSeeder   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 31 1
1
<?php
2
3
namespace App\Modules\V1\Acl\Database\Seeds;
4
5
use Illuminate\Database\Seeder;
6
7
class AssignRelationsSeeder extends Seeder
8
{
9
    /**
10
     * Run the database seeds.
11
     *
12
     * @return void
13
     */
14
    public function run()
15
    {
16
    	$adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
17
		$adminUserId  = \DB::table('users')->where('email', '[email protected]')->select('id')->first()->id;
18
19
		/**
20
		 * Assign users to groups.
21
		 */
22
		\DB::table('users_groups')->insert(
23
			[
24
			'user_id'    => $adminUserId,
25
			'group_id'   => $adminGroupId,
26
			'created_at' => \DB::raw('NOW()'),
27
			'updated_at' => \DB::raw('NOW()')
28
			]
29
        );
30
31
        /**
32
		 * Assign the permissions to the admin group.
33
		 */
34
        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) {
35
        	\DB::table('groups_permissions')->insert(
36
				[
37
				'permission_id' => $permission->id,
38
				'group_id'      => $adminGroupId,
39
				'created_at'    => \DB::raw('NOW()'),
40
				'updated_at'    => \DB::raw('NOW()')
41
				]
42
			);
43
        });
44
    }
45
}
46