Completed
Push — master ( b985db...bee0c3 )
by Christian
05:14
created

CreateSpatieModelHasRolesTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 42
ccs 22
cts 22
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 23 2
A down() 0 5 1
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateSpatieModelHasRolesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14 51
    public function up()
15
    {
16 51
        $tableNames = config('permission.table_names');
17 51
        $columnNames = config('permission.column_names');
18
19
        Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
20 51
            $table->unsignedBigInteger('role_id');
21 51
            $table->string('model_type');
22 51
            $table->unsignedBigInteger($columnNames['model_morph_key']);
23 51
            $table->index([$columnNames['model_morph_key'], 'model_type',]);
24 51
            $table->foreign('role_id')
25 51
                ->references('id')
26 51
                ->on($tableNames['roles'])
27 51
                ->onDelete('cascade');
28 51
            $table->primary(
29 51
                ['role_id', $columnNames['model_morph_key'], 'model_type'],
30 51
                'model_has_roles_role_model_type_primary'
31
            );
32 51
        });
33
34 51
        app('cache')
35 51
            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
36 51
            ->forget(config('permission.cache.key'));
37 51
    }
38
39
    /**
40
     * Reverse the migrations.
41
     *
42
     * @return void
43
     */
44 51
    public function down()
45
    {
46 51
        $tableNames = config('permission.table_names');
47
48 51
        Schema::drop($tableNames['model_has_roles']);
49 51
    }
50
}
51