Completed
Push — master ( 149996...1d6fcb )
by wen
11:13
created

RbacTableSeeder::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Seeder;
4
use Carbon\Carbon;
5
6
class RbacTableSeeder 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...
7
{
8
9
    private $managerModel;
10
11
    public function __construct()
12
    {
13
        $guard              = config('admin.guard');
14
        $provider           = config("auth.guards.{$guard}.provider");
15
        $managerModelName   = config("auth.providers.{$provider}.model");
16
        $this->managerModel = new $managerModelName();
17
    }
18
19
    /**
20
     * Run the database seeds.
21
     *
22
     * @return void
23
     */
24
    public function run()
25
    {
26
        $this->insertManager();
27
28
        $database = file_get_contents(__DIR__ . '/' . 'rbac.sql');
29
        $prefix   = env('DB_PREFIX', '');
30
        $database = str_replace('sco_', $prefix, $database);
31
32
        DB::connection()->getPdo()->exec($database);
33
    }
34
35
    private function insertManager()
36
    {
37
        $managerTable = $this->managerModel->getTable();
38
        if ($managerTable != 'users') {
39
            DB::table($managerTable)->insert([
40
                'id'         => 1,
41
                'name'       => 'admin',
42
                'email'      => '[email protected]',
43
                'password'   => bcrypt('123456'),
44
                'created_at' => Carbon::now(),
45
                'updated_at' => Carbon::now(),
46
            ]);
47
        }
48
    }
49
}
50