3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
7 class RemoveHiddenRoles extends Migration
16 // Remove the hidden property from roles
17 Schema::table('roles', function (Blueprint $table) {
18 $table->dropColumn('hidden');
21 // Add column to mark system users
22 Schema::table('users', function (Blueprint $table) {
23 $table->string('system_name')->nullable()->index();
26 // Insert our new public system user.
27 $publicUserId = DB::table('users')->insertGetId([
30 'system_name' => 'public',
31 'email_confirmed' => true,
32 'created_at' => \Carbon\Carbon::now(),
33 'updated_at' => \Carbon\Carbon::now(),
36 // Get the public role
37 $publicRole = DB::table('roles')->where('system_name', '=', 'public')->first();
39 // Connect the new public user to the public role
40 DB::table('role_user')->insert([
41 'user_id' => $publicUserId,
42 'role_id' => $publicRole->id,
47 * Reverse the migrations.
51 public function down()
53 Schema::table('roles', function (Blueprint $table) {
54 $table->boolean('hidden')->default(false);
55 $table->index('hidden');
58 DB::table('users')->where('system_name', '=', 'public')->delete();
60 Schema::table('users', function (Blueprint $table) {
61 $table->dropColumn('system_name');
64 DB::table('roles')->where('system_name', '=', 'public')->update(['hidden' => true]);