Passed
Branch master (98ac03)
by Christian
04:34
created

CreateSpatieRoleHasPermissionsTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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