| Total Complexity | 3 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CreatePermissionUserTable 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.permissionsUserTable'); |
||
| 18 | $permissionsTable = config('roles.permissionsTable'); |
||
| 19 | $tableCheck = Schema::connection($connection)->hasTable($table); |
||
| 20 | $userTable = app(config('auth.providers.users.model'))->getTable(); |
||
|
|
|||
| 21 | |||
| 22 | if (!$tableCheck) { |
||
| 23 | Schema::connection($connection)->create($table, function (Blueprint $table) use ($permissionsTable, $userTable) { |
||
| 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->unsignedBigInteger('user_id')->unsigned()->index(); |
||
| 28 | $table->foreign('user_id')->references('id')->on($userTable)->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 |