Completed
Push — master ( 02d451...2ce496 )
by Sherif
02: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
use Illuminate\Database\Seeder;
4
5
class AssignRelationsSeeder extends Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * Run the database seeds.
9
     *
10
     * @return void
11
     */
12
    public function run()
13
    {
14
    	$adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id;
15
		$adminUserId  = DB::table('users')->whereIn('email', '[email protected]')->select('id')->first()->id;
16
17
		/**
18
		 * Assign users to groups.
19
		 */
20
		DB::table('users_groups')->insert(
21
			[
22
			'user_id'    => $adminUserId,
23
			'group_id'   => $adminGroupId,
24
			'created_at' => \DB::raw('NOW()'),
25
			'updated_at' => \DB::raw('NOW()')
26
			]
27
        );
28
29
        /**
30
		 * Assign the permissions to the admin group.
31
		 */
32
        DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) {
33
        	DB::table('groups_permissions')->insert(
34
				[
35
				'permission_id' => $permission->id,
36
				'group_id'      => $adminGroupId,
37
				'created_at'    => \DB::raw('NOW()'),
38
				'updated_at'    => \DB::raw('NOW()')
39
				]
40
			);
41
        });
42
    }
43
}
44