increments('id'); $table->timestamps(); $table->softDeletes(); }); Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('account_id')->index(); $table->string('first_name')->nullable(); $table->string('last_name')->nullable(); $table->string('phone')->nullable(); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('confirmation_code')->nullable(); $table->boolean('registered')->default(false); $table->boolean('confirmed')->default(false); $table->integer('theme_id')->nullable(); $table->smallInteger('failed_logins')->nullable(); $table->string('referral_code')->nullable(); $table->string('oauth_user_id')->nullable()->unique(); $table->unsignedInteger('oauth_provider_id')->nullable()->unique(); $table->string('google_2fa_secret')->nullable(); $table->string('accepted_terms_version')->nullable(); $table->string('avatar', 255)->default(''); $table->unsignedInteger('avatar_width')->nullable(); $table->unsignedInteger('avatar_height')->nullable(); $table->unsignedInteger('avatar_size')->nullable(); $table->text('signature'); $table->string('password'); $table->rememberToken(); $table->timestamps(); $table->softDeletes(); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); }); Schema::create('user_accounts', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('account_id')->index(); $table->unsignedInteger('user_id')->index(); $table->text('permissions'); $table->boolean('is_owner'); $table->boolean('is_admin'); $table->boolean('is_locked'); // locks user out of account $table->boolean('is_default'); //default account to present to the user $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); }); Schema::create('account_gateways', function($t) { $t->increments('id'); $t->unsignedInteger('account_id'); $t->unsignedInteger('user_id'); $t->unsignedInteger('gateway_id'); $t->timestamps(); $t->softDeletes(); $t->text('config'); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); //$t->foreign('gateway_id')->references('id')->on('gateways'); $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $t->unique( array('account_id') ); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('account_gateways'); Schema::dropIfExists('user_accounts'); Schema::dropIfExists('users'); Schema::dropIfExists('accounts'); } }