FEATURE #2048: add basics of permissions management

This commit is contained in:
Michal Kváček
2017-08-10 23:18:53 +02:00
parent f702ba3a29
commit cccdbda543
18 changed files with 483 additions and 147 deletions
@@ -0,0 +1,65 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePermissionsTable extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')
->nullable()
->unsigned();
$table->string('string_id')
->unique();
$table->string('name');
$table->string('group')
->nullable(true);
});
Schema::table('permissions', function (Blueprint $table) {
$table->foreign('parent_id')
->references('id')
->on('permissions')
->onDelete('set null')
->onUpdate('cascade');
});
Schema::create('user_has_permissions', function (Blueprint $table) {
$table->integer('user_id');
$table->integer('permission_id')
->unsigned();
});
Schema::table('user_has_permissions', function (Blueprint $table) {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('permission_id')
->references('id')
->on('permissions')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::drop('user_has_permissions');
Schema::drop('permissions');
}
}