first commit
This commit is contained in:
59
database/migrations/2018_03_07_141643_create_roles.php
Normal file
59
database/migrations/2018_03_07_141643_create_roles.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use App\Models\Role;
|
||||
use App\Models\Rule;
|
||||
|
||||
class CreateRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('role', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name', 255);
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->foreign('role_id')->references('id')->on('role');
|
||||
});
|
||||
|
||||
|
||||
Schema::create('rule', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('role_id');
|
||||
$table->string('object', 50);
|
||||
$table->string('action', 50);
|
||||
$table->boolean('allow')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['role_id', 'object', 'action']);
|
||||
$table->foreign('role_id')->references('id')->on('role')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropForeign('users_role_id_foreign');
|
||||
$table->dropColumn('role_id');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('rule');
|
||||
Schema::dropIfExists('role');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user