renameColumn('regex', 'rules'); }); DB::transaction(function () { foreach (ServiceVariable::all() as $variable) { $variable->rules = ($variable->required) ? 'required|regex:' . $variable->rules : 'regex:' . $variable->regex; $variable->save(); } }); Schema::table('service_variables', function (Blueprint $table) { $table->dropColumn('required'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('service_variables', function (Blueprint $table) { $table->renameColumn('rules', 'regex'); $table->boolean('required')->default(true)->before('regex'); }); DB::transaction(function () { foreach (ServiceVariable::all() as $variable) { $variable->regex = str_replace(['required|regex:', 'regex:'], '', $variable->regex); $variable->save(); } }); } }