Passed
Push — master ( 7e2e0f...b985db )
by Christian
02:40
created

CreateSpatieModelHasPermissionsTable::up()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 27

Duplication

Lines 27
Ratio 100 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 0
Metric Value
dl 27
loc 27
ccs 19
cts 19
cp 1
rs 9.488
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7 View Code Duplication
class CreateSpatieModelHasPermissionsTable extends Migration
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) {
20 51
            $table->unsignedBigInteger('permission_id');
21
22 51
            $table->string('model_type');
23 51
            $table->unsignedBigInteger($columnNames['model_morph_key']);
24 51
            $table->index([$columnNames['model_morph_key'], 'model_type',]);
25
26 51
            $table->foreign('permission_id')
27 51
                ->references('id')
28 51
                ->on($tableNames['permissions'])
29 51
                ->onDelete('cascade');
30
31 51
            $table->primary(
32 51
                ['permission_id', $columnNames['model_morph_key'], 'model_type'],
33 51
                'model_has_permissions_permission_model_type_primary'
34
            );
35 51
        });
36
37 51
        app('cache')
38 51
            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
39 51
            ->forget(config('permission.cache.key'));
40 51
    }
41
42
    /**
43
     * Reverse the migrations.
44
     *
45
     * @return void
46
     */
47 51
    public function down()
48
    {
49 51
        $tableNames = config('permission.table_names');
50
51 51
        Schema::drop($tableNames['model_has_permissions']);
52 51
    }
53
}
54