| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Illuminate\Database\Migrations\Migration; | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | use Illuminate\Database\Schema\Blueprint; | 
					
						
							|  |  |  | use Illuminate\Support\Facades\Schema; | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class RemoveHiddenRoles extends Migration | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Run the migrations. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function up() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Remove the hidden property from roles
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         Schema::table('roles', function (Blueprint $table) { | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |             $table->dropColumn('hidden'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Add column to mark system users
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         Schema::table('users', function (Blueprint $table) { | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |             $table->string('system_name')->nullable()->index(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Insert our new public system user.
 | 
					
						
							|  |  |  |         $publicUserId = DB::table('users')->insertGetId([ | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'email'           => 'guest@example.com', | 
					
						
							|  |  |  |             'name'            => 'Guest', | 
					
						
							|  |  |  |             'system_name'     => 'public', | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |             'email_confirmed' => true, | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'created_at'      => \Carbon\Carbon::now(), | 
					
						
							|  |  |  |             'updated_at'      => \Carbon\Carbon::now(), | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |         // Get the public role
 | 
					
						
							|  |  |  |         $publicRole = DB::table('roles')->where('system_name', '=', 'public')->first(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Connect the new public user to the public role
 | 
					
						
							|  |  |  |         DB::table('role_user')->insert([ | 
					
						
							|  |  |  |             'user_id' => $publicUserId, | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'role_id' => $publicRole->id, | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Reverse the migrations. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function down() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         Schema::table('roles', function (Blueprint $table) { | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |             $table->boolean('hidden')->default(false); | 
					
						
							|  |  |  |             $table->index('hidden'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         DB::table('users')->where('system_name', '=', 'public')->delete(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         Schema::table('users', function (Blueprint $table) { | 
					
						
							| 
									
										
										
										
											2016-09-29 19:43:46 +08:00
										 |  |  |             $table->dropColumn('system_name'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         DB::table('roles')->where('system_name', '=', 'public')->update(['hidden' => true]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |