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

CreateSpatieRoleHasPermissionsTable::up()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
ccs 17
cts 17
cp 1
crap 2
rs 9.7333
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateSpatieRoleHasPermissionsTable 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
18
        Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
19 51
            $table->unsignedBigInteger('permission_id');
20 51
            $table->unsignedBigInteger('role_id');
21 51
            $table->foreign('permission_id')
22 51
                ->references('id')
23 51
                ->on($tableNames['permissions'])
24 51
                ->onDelete('cascade');
25 51
            $table->foreign('role_id')
26 51
                ->references('id')
27 51
                ->on($tableNames['roles'])
28 51
                ->onDelete('cascade');
29 51
            $table->primary(['permission_id', 'role_id']);
30 51
        });
31
32 51
        app('cache')
33 51
            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
34 51
            ->forget(config('permission.cache.key'));
35 51
    }
36
37
    /**
38
     * Reverse the migrations.
39
     *
40
     * @return void
41
     */
42 51
    public function down()
43
    {
44 51
        $tableNames = config('permission.table_names');
45
46 51
        Schema::drop($tableNames['role_has_permissions']);
47 51
    }
48
}
49