use laratrust to replace entrust #78
This commit is contained in:
@@ -6,7 +6,6 @@ use Faker\Generator as Faker;
|
||||
* Add any number of airports. Don't really care if they're real or not
|
||||
*/
|
||||
$factory->define(App\Models\Airport::class, function (Faker $faker) {
|
||||
|
||||
return [
|
||||
'id' => strtoupper($faker->unique()->text(5)),
|
||||
'icao' => function(array $apt) { return $apt['id']; },
|
||||
|
||||
@@ -37,68 +37,6 @@ class CreateUsersTable extends Migration
|
||||
$table->index('email');
|
||||
$table->index('api_key');
|
||||
});
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +47,5 @@ class CreateUsersTable extends Migration
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('permission_role');
|
||||
Schema::dropIfExists('permissions');
|
||||
Schema::dropIfExists('role_user');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class RolesPermissionsTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 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 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 roles to users and teams (Many To Many Polymorphic)
|
||||
Schema::create('role_user', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->string('user_type');
|
||||
|
||||
$table->foreign('role_id')->references('id')->on('roles')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
|
||||
$table->primary(['user_id', 'role_id', 'user_type']);
|
||||
});
|
||||
|
||||
// Create table for associating permissions to users (Many To Many Polymorphic)
|
||||
Schema::create('permission_user', function (Blueprint $table) {
|
||||
$table->unsignedInteger('permission_id');
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->string('user_type');
|
||||
|
||||
$table->foreign('permission_id')->references('id')->on('permissions')
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
|
||||
$table->primary(['user_id', 'permission_id', 'user_type']);
|
||||
});
|
||||
|
||||
// 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('permission_user');
|
||||
Schema::dropIfExists('permission_role');
|
||||
Schema::dropIfExists('permissions');
|
||||
Schema::dropIfExists('role_user');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
}
|
||||
@@ -55,12 +55,16 @@ users:
|
||||
role_user:
|
||||
- user_id: 1
|
||||
role_id: 1
|
||||
user_type: App\Models\User
|
||||
- user_id: 1
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 2
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
- user_id: 3
|
||||
role_id: 2
|
||||
user_type: App\Models\User
|
||||
|
||||
# ranks
|
||||
ranks:
|
||||
|
||||
Reference in New Issue
Block a user