Total Complexity | 3 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class CreateRoleUserTable extends Migration |
||
8 | { |
||
9 | /** |
||
10 | * Run the migrations. |
||
11 | * |
||
12 | * @return void |
||
13 | */ |
||
14 | public function up() |
||
15 | { |
||
16 | $connection = config('roles.connection'); |
||
17 | $table = config('roles.roleUserTable'); |
||
18 | $rolesTable = config('roles.rolesTable'); |
||
19 | $tableCheck = Schema::connection($connection)->hasTable($table); |
||
20 | |||
21 | if (!$tableCheck) { |
||
22 | Schema::connection($connection)->create($table, function (Blueprint $table) use ($rolesTable) { |
||
23 | $table->increments('id')->unsigned(); |
||
24 | $table->integer('role_id')->unsigned()->index(); |
||
25 | $table->foreign('role_id')->references('id')->on($rolesTable)->onDelete('cascade'); |
||
26 | $table->unsignedBigInteger('user_id')->unsigned()->index(); |
||
27 | $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
||
28 | $table->timestamps(); |
||
29 | $table->softDeletes(); |
||
30 | }); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Reverse the migrations. |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | public function down() |
||
44 | } |
||
45 | } |
||
46 |