include entrust and some seed data for admin role/user
This commit is contained in:
@@ -15,9 +15,7 @@ class CreateUsersTable extends Migration
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->string('first_name')->nullable();
|
||||
$table->string('last_name')->nullable();
|
||||
$table->string('name')->nullable();
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->string('code')->nullable();
|
||||
@@ -32,6 +30,53 @@ class CreateUsersTable extends Migration
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// 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->integer('user_id')->unsigned();
|
||||
$table->integer('role_id')->unsigned();
|
||||
|
||||
$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']);
|
||||
});
|
||||
|
||||
// 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->integer('permission_id')->unsigned();
|
||||
$table->integer('role_id')->unsigned();
|
||||
|
||||
$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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,5 +87,9 @@ class CreateUsersTable extends Migration
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
Schema::drop('permission_role');
|
||||
Schema::drop('permissions');
|
||||
Schema::drop('role_user');
|
||||
Schema::drop('roles');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeds;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AircraftClassesSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
37
database/seeds/InitialDataSeeder.php
Normal file
37
database/seeds/InitialDataSeeder.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InitialDataSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->user_seeder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an initial admin user and roles
|
||||
*/
|
||||
protected function user_seeder()
|
||||
{
|
||||
# 2 main groups
|
||||
DB::table('roles')->insert(['id' => 1, 'name' => 'Administrators']);
|
||||
DB::table('roles')->insert(['id' => 2, 'name' => 'Pilots']);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'name' => 'Admin User',
|
||||
'email' => 'admin@phpvms.net',
|
||||
'password' => bcrypt('admin'),
|
||||
]);
|
||||
|
||||
DB::table('role_user')->insert([
|
||||
'user_id' => 1, 'role_id' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user