| Total Complexity | 3 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class CreatePermissionRoleTable 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.permissionsRoleTable'); |
||
| 18 | $permissionsTable = config('roles.permissionsTable'); |
||
| 19 | $rolesTable = config('roles.rolesTable'); |
||
| 20 | $tableCheck = Schema::connection($connection)->hasTable($table); |
||
| 21 | |||
| 22 | if (!$tableCheck) { |
||
| 23 | Schema::connection($connection)->create($table, function (Blueprint $table) use ($permissionsTable, $rolesTable) { |
||
| 24 | $table->increments('id')->unsigned(); |
||
| 25 | $table->integer('permission_id')->unsigned()->index(); |
||
| 26 | $table->foreign('permission_id')->references('id')->on($permissionsTable)->onDelete('cascade'); |
||
| 27 | $table->integer('role_id')->unsigned()->index(); |
||
| 28 | $table->foreign('role_id')->references('id')->on($rolesTable)->onDelete('cascade'); |
||
| 29 | $table->timestamps(); |
||
| 30 | $table->softDeletes(); |
||
| 31 | }); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Reverse the migrations. |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function down() |
||
| 45 | } |
||
| 46 | } |
||
| 47 |