FEATURE #2048: add basics of permissions management
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user