@@ -15,20 +15,38 @@ public function up()
15
15
16
16
Schema::table('{{ $laratrust [' role_user_table' ] } } ', function (Blueprint $table) {
17
17
// Drop user foreign key and primary with role_id
18
- $table->dropForeign('{{ $laratrust [' role_user_table' ] } } _{{ $laratrust [' user_foreign_key' ] } } _foreign');
18
+ $table->dropForeign(['{{ $laratrust [' user_foreign_key' ] } } ']);
19
+ $table->dropForeign(['{{ $laratrust [' role_foreign_key' ] } } ']);
19
20
$table->dropPrimary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' role_foreign_key' ] } } ']);
20
21
21
22
$table->string('user_type');
23
+ });
24
+
25
+ DB::table('{{ $laratrust [' role_user_table' ] } } ')->update(['user_type' => '{{ get_class ($user ) } } ']);
26
+
27
+ Schema::table('{{ $laratrust [' role_user_table' ] } } ', function (Blueprint $table) {
28
+ $table->foreign('{{ $laratrust [' role_foreign_key' ] } } ')->references('id')->on('{{ $laratrust [' roles_table' ] } } ')
29
+ ->onUpdate('cascade')->onDelete('cascade');
22
30
$table->primary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' role_foreign_key' ] } } ', 'user_type']);
23
31
});
24
32
33
+
34
+
25
35
Schema::table('{{ $laratrust [' permission_user_table' ] } } ', function (Blueprint $table) {
26
36
// Drop user foreign key and primary with permission_id
27
- $table->dropForeign('{{ $laratrust [' permission_user_table' ] } } _{{ $laratrust [' user_foreign_key' ] } } _foreign');
28
- $table->dropPrimary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' permission_foreign_key' ] } } ']);
37
+ $table->dropForeign(['{{ $laratrust [' user_foreign_key' ] } } ']);
38
+ $table->dropForeign(['{{ $laratrust [' permission_foreign_key' ] } } ']);
39
+ $table->dropPrimary(['{{ $laratrust [' permission_foreign_key' ] } } ', '{{ $laratrust [' user_foreign_key' ] } } ']);
29
40
30
41
$table->string('user_type');
31
- $table->primary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' permission_foreign_key' ] } } ', 'user_type']);
42
+ });
43
+
44
+ DB::table('{{ $laratrust [' permission_user_table' ] } } ')->update(['user_type' => '{{ get_class ($user ) } } ']);
45
+
46
+ Schema::table('{{ $laratrust [' permission_user_table' ] } } ', function (Blueprint $table) {
47
+ $table->foreign('{{ $laratrust [' permission_foreign_key' ] } } ')->references('id')->on('{{ $laratrust [' permissions_table' ] } } ')
48
+ ->onUpdate('cascade')->onDelete('cascade');
49
+ $table->primary(['{{ $laratrust [' permission_foreign_key' ] } } ', '{{ $laratrust [' user_foreign_key' ] } } ', 'user_type']);
32
50
});
33
51
}
34
52
@@ -40,21 +58,27 @@ public function up()
40
58
public function down()
41
59
{
42
60
Schema::table('{{ $laratrust [' role_user_table' ] } } ', function (Blueprint $table) {
61
+ $table->dropForeign(['{{ $laratrust [' role_foreign_key' ] } } ']);
43
62
$table->dropPrimary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' role_foreign_key' ] } } ', 'user_type']);
44
63
$table->dropColumn('user_type');
45
64
46
65
$table->foreign('{{ $laratrust [' user_foreign_key' ] } } ')->references('{{ $user -> getKeyName () } } ')->on('{{ $user -> getTable () } } ')
47
66
->onUpdate('cascade')->onDelete('cascade');
67
+ $table->foreign('{{ $laratrust [' role_foreign_key' ] } } ')->references('id')->on('{{ $laratrust [' roles_table' ] } } ')
68
+ ->onUpdate('cascade')->onDelete('cascade');
48
69
$table->primary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' role_foreign_key' ] } } ']);
49
70
});
50
71
51
72
Schema::table('{{ $laratrust [' permission_user_table' ] } } ', function (Blueprint $table) {
52
- $table->dropPrimary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' permission_foreign_key' ] } } ', 'user_type']);
73
+ $table->dropForeign(['{{ $laratrust [' permission_foreign_key' ] } } ']);
74
+ $table->dropPrimary(['{{ $laratrust [' permission_foreign_key' ] } } ', '{{ $laratrust [' user_foreign_key' ] } } ', 'user_type']);
53
75
$table->dropColumn('user_type');
54
76
55
77
$table->foreign('{{ $laratrust [' user_foreign_key' ] } } ')->references('{{ $user -> getKeyName () } } ')->on('{{ $user -> getTable () } } ')
56
78
->onUpdate('cascade')->onDelete('cascade');
57
- $table->primary(['{{ $laratrust [' user_foreign_key' ] } } ', '{{ $laratrust [' permission_foreign_key' ] } } ']);
79
+ $table->foreign('{{ $laratrust [' permission_foreign_key' ] } } ')->references('id')->on('{{ $laratrust [' permissions_table' ] } } ')
80
+ ->onUpdate('cascade')->onDelete('cascade');
81
+ $table->primary(['{{ $laratrust [' permission_foreign_key' ] } } ', '{{ $laratrust [' user_foreign_key' ] } } ']);
58
82
});
59
83
}
60
84
}
0 commit comments