2023-07-02 16:17:18 +06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
return new class extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function up()
|
|
|
|
{
|
|
|
|
Schema::create('roles', function (Blueprint $table) {
|
|
|
|
$table->id();
|
|
|
|
$table->string('name');
|
2023-07-12 22:30:05 +06:00
|
|
|
$table->string('code')->unique();
|
2023-07-02 16:17:18 +06:00
|
|
|
$table->timestamps();
|
|
|
|
$table->softDeletes();
|
|
|
|
});
|
|
|
|
|
|
|
|
DB::table('roles')->insert([
|
|
|
|
'name' => 'Administrator',
|
2023-07-12 22:30:05 +06:00
|
|
|
'code' => 'admin',
|
2023-07-02 16:17:18 +06:00
|
|
|
'created_at' => Carbon::now(),
|
|
|
|
'updated_at' => Carbon::now()
|
|
|
|
]);
|
|
|
|
|
|
|
|
Schema::create('role_user', function (Blueprint $table) {
|
|
|
|
$table->unsignedBigInteger('user_id')->index();
|
|
|
|
$table->unsignedBigInteger('role_id');
|
|
|
|
$table->foreign('user_id')->references('id')->on('users');
|
|
|
|
$table->foreign('role_id')->references('id')->on('roles');
|
|
|
|
$table->primary(['user_id', 'role_id']);
|
|
|
|
});
|
|
|
|
|
|
|
|
Schema::create('role_permission', function (Blueprint $table) {
|
|
|
|
$table->id();
|
|
|
|
$table->unsignedBigInteger('role_id')->index();
|
|
|
|
$table->string('permission');
|
|
|
|
$table->foreign('role_id')->references('id')->on('roles');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function down()
|
|
|
|
{
|
|
|
|
Schema::dropIfExists('role_permission');
|
|
|
|
Schema::dropIfExists('role_user');
|
|
|
|
Schema::dropIfExists('roles');
|
|
|
|
}
|
|
|
|
};
|