SentinelUserSeedTableSeeder::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 23
rs 9.0857
cc 1
eloc 11
nc 1
nop 0
1
<?php namespace Modules\User\Database\Seeders;
2
3
use Cartalyst\Sentinel\Laravel\Facades\Activation;
4
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Seeder;
7
8
class SentinelUserSeedTableSeeder extends Seeder
9
{
10
    /**
11
     * Run the database seeds.
12
     *
13
     * @return void
14
     */
15
    public function run()
16
    {
17
        Model::unguard();
18
19
        // Create an admin user
20
        $user = Sentinel::create(
21
            [
22
                'email' => '[email protected]',
23
                'password' => 'test',
24
                'first_name' => 'Nicolas',
25
                'last_name' => 'Widart',
26
            ]
27
        );
28
        // Activate the admin directly
29
        $activation = Activation::create($user);
30
        Activation::complete($user, $activation->code);
31
32
        // Find the group using the group id
33
        $adminGroup = Sentinel::findRoleBySlug('admin');
34
35
        // Assign the group to the user
36
        $adminGroup->users()->attach($user);
37
    }
38
}
39