Completed
Push — master ( 02d451...2ce496 )
by Sherif
02:39
created

AssignRelationsSeeder::run()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
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