increments('id'); $table->string('name')->nullable(); $table->string('email')->unique(); $table->string('password'); $table->string('apikey', 40)->nullable(); $table->unsignedInteger('airline_id'); $table->unsignedInteger('rank_id'); $table->string('home_airport_id', 5)->nullable(); $table->string('curr_airport_id', 5)->nullable(); $table->string('last_pirep_id', 12)->nullable(); $table->unsignedBigInteger('flights')->default(0); $table->unsignedBigInteger('flight_time')->default(0); $table->decimal('balance', 19)->nullable(); $table->string('timezone', 64)->nullable(); $table->boolean('active')->nullable(); $table->rememberToken(); $table->timestamps(); $table->softDeletes(); $table->index('email'); $table->index('apikey'); }); // Create table for storing roles Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name')->unique(); $table->string('display_name')->nullable(); $table->string('description')->nullable(); $table->timestamps(); }); // Create table for associating roles to users (Many-to-Many) Schema::create('role_user', function (Blueprint $table) { $table->unsignedInteger('user_id'); $table->unsignedInteger('role_id'); $table->foreign('user_id')->references('id')->on('users') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('role_id')->references('id')->on('roles') ->onUpdate('cascade')->onDelete('cascade'); $table->primary(['user_id', 'role_id']); $table->index(['role_id', 'user_id']); }); // Create table for storing permissions Schema::create('permissions', function (Blueprint $table) { $table->increments('id'); $table->string('name')->unique(); $table->string('display_name')->nullable(); $table->string('description')->nullable(); $table->timestamps(); }); // Create table for associating permissions to roles (Many-to-Many) Schema::create('permission_role', function (Blueprint $table) { $table->unsignedInteger('permission_id'); $table->unsignedInteger('role_id'); $table->foreign('permission_id')->references('id')->on('permissions') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('role_id')->references('id')->on('roles') ->onUpdate('cascade')->onDelete('cascade'); $table->primary(['permission_id', 'role_id']); }); # create a default user/role $roles = [ [ 'id' => 1, 'name' => 'admin', 'display_name' => 'Administrators', ], [ 'id' => 2, 'name' => 'user', 'display_name' => 'Pilot' ], ]; $this->addData('roles', $roles); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('users'); Schema::dropIfExists('permission_role'); Schema::dropIfExists('permissions'); Schema::dropIfExists('role_user'); Schema::dropIfExists('roles'); } }