Skip to content

Commit

Permalink
Added timestamps to pivot tables
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodiogenes committed May 5, 2020
1 parent 20e3a5d commit 59d07f0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,94 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAuthorizationTables extends Migration
{
class CreateAuthorizationTables extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
public function up() {
Schema::create('roles', function(Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('name');
$table->string('label')->nullable();
$table->string('name')->unique();
$table->string('label');
$table->boolean('protected')->default(false);
});

Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
Schema::create('permissions', function(Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('name');
$table->string('label')->nullable();
$table->string('name')->unique();
$table->string('label');
$table->string('group');
});

Schema::create('permission_role', function (Blueprint $table) {
$table->unsignedInteger('permission_id');
$table->unsignedInteger('role_id');
Schema::create('permission_role', function(Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('role_id');
$table->timestamps();

$table->primary(['permission_id', 'role_id']);
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
});

Schema::create('permission_user', function (Blueprint $table) {
$table->unsignedInteger('permission_id');
$table->unsignedInteger('user_id');
Schema::create('user_role', function(Blueprint $table) {
$table->unsignedBigInteger('role_id');
$table->unsignedBigInteger('user_id');
$table->timestamps();

$table->primary(['role_id', 'user_id']);
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users');
});

Schema::create('user_permission', function(Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('user_id');
$table->timestamps();

$table->primary(['permission_id', 'user_id']);
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users');
});

Schema::create('role_user', function (Blueprint $table) {
$table->unsignedInteger('role_id');
$table->unsignedInteger('user_id');
/*
Schema::create('admin_user_role', function(Blueprint $table) {
$table->unsignedBigInteger('role_id');
$table->unsignedBigInteger('admin_user_id');
$table->timestamps();
$table->primary(['role_id', 'user_id']);
$table->primary(['role_id', 'admin_user_id']);
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('admin_user_id')->references('id')->on('admin_users');
});
Schema::create('admin_user_permission', function(Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('admin_user_id');
$table->timestamps();
$table->primary(['permission_id', 'admin_user_id']);
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->foreign('admin_user_id')->references('id')->on('admin_users');
});*/

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('role_user');
Schema::dropIfExists('permission_role');
Schema::dropIfExists('permission_user');
public function down() {
// Schema::dropIfExists('admin_user_permission');
// Schema::dropIfExists('admin_user_role');
Schema::dropIfExists('user_permission');
Schema::dropIfExists('user_role');
Schema::dropIfExists('permissions');
Schema::dropIfExists('roles');

}
}
2 changes: 1 addition & 1 deletion src/Traits/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ trait HasPermissions
*/
public function permissions()
{
return $this->belongsToMany(Authorization::permissionModel());
return $this->belongsToMany(Authorization::permissionModel())->withTimestamps();
}
}
2 changes: 1 addition & 1 deletion src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ trait HasRoles
*/
public function roles()
{
return $this->belongsToMany(Authorization::roleModel());
return $this->belongsToMany(Authorization::roleModel())->withTimestamps();
}
}

0 comments on commit 59d07f0

Please sign in to comment.